|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +/* globals support: false */ |
| 4 | + |
3 | 5 | describe('ngMock', function() {
|
4 | 6 | var noop = angular.noop;
|
5 | 7 |
|
@@ -1888,6 +1890,52 @@ describe('ngMock', function() {
|
1888 | 1890 | expect(called).toBe(true);
|
1889 | 1891 | });
|
1890 | 1892 | });
|
| 1893 | + |
| 1894 | + it('should support assigning bindings when a value is returned from the constructor', |
| 1895 | + function() { |
| 1896 | + var called = false; |
| 1897 | + var data = [ |
| 1898 | + { name: 'derp1', id: 0 }, |
| 1899 | + { name: 'testname', id: 1 }, |
| 1900 | + { name: 'flurp', id: 2 } |
| 1901 | + ]; |
| 1902 | + module(function($controllerProvider) { |
| 1903 | + $controllerProvider.register('testCtrl', function() { |
| 1904 | + called = true; |
| 1905 | + expect(this.data).toBe(data); |
| 1906 | + |
| 1907 | + return {}; |
| 1908 | + }); |
| 1909 | + }); |
| 1910 | + inject(function($controller, $rootScope) { |
| 1911 | + var ctrl = $controller('testCtrl', { scope: $rootScope }, { data: data }); |
| 1912 | + expect(ctrl.data).toBe(data); |
| 1913 | + expect(called).toBe(true); |
| 1914 | + }); |
| 1915 | + } |
| 1916 | + ); |
| 1917 | + |
| 1918 | + if (/chrome/.test(navigator.userAgent)) { |
| 1919 | + it('should support assigning bindings to class-based controller', function() { |
| 1920 | + var called = false; |
| 1921 | + var data = [ |
| 1922 | + { name: 'derp1', id: 0 }, |
| 1923 | + { name: 'testname', id: 1 }, |
| 1924 | + { name: 'flurp', id: 2 } |
| 1925 | + ]; |
| 1926 | + module(function($controllerProvider) { |
| 1927 | + //jshint evil: true |
| 1928 | + var TestCtrl = eval('(class { constructor() { called = true; } })'); |
| 1929 | + //jshint evil: false |
| 1930 | + $controllerProvider.register('testCtrl', TestCtrl); |
| 1931 | + }); |
| 1932 | + inject(function($controller, $rootScope) { |
| 1933 | + var ctrl = $controller('testCtrl', { scope: $rootScope }, { data: data }); |
| 1934 | + expect(ctrl.data).toBe(data); |
| 1935 | + expect(called).toBe(true); |
| 1936 | + }); |
| 1937 | + }); |
| 1938 | + } |
1891 | 1939 | });
|
1892 | 1940 |
|
1893 | 1941 |
|
|
0 commit comments