|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +/* globals support: false */ |
| 4 | + |
3 | 5 | describe('ngMock', function() {
|
4 | 6 | var noop = angular.noop;
|
5 | 7 |
|
@@ -1919,6 +1921,52 @@ describe('ngMock', function() {
|
1919 | 1921 | expect(called).toBe(true);
|
1920 | 1922 | });
|
1921 | 1923 | });
|
| 1924 | + |
| 1925 | + it('should support assigning bindings when a value is returned from the constructor', |
| 1926 | + function() { |
| 1927 | + var called = false; |
| 1928 | + var data = [ |
| 1929 | + { name: 'derp1', id: 0 }, |
| 1930 | + { name: 'testname', id: 1 }, |
| 1931 | + { name: 'flurp', id: 2 } |
| 1932 | + ]; |
| 1933 | + module(function($controllerProvider) { |
| 1934 | + $controllerProvider.register('testCtrl', function() { |
| 1935 | + called = true; |
| 1936 | + expect(this.data).toBe(data); |
| 1937 | + |
| 1938 | + return {}; |
| 1939 | + }); |
| 1940 | + }); |
| 1941 | + inject(function($controller, $rootScope) { |
| 1942 | + var ctrl = $controller('testCtrl', { scope: $rootScope }, { data: data }); |
| 1943 | + expect(ctrl.data).toBe(data); |
| 1944 | + expect(called).toBe(true); |
| 1945 | + }); |
| 1946 | + } |
| 1947 | + ); |
| 1948 | + |
| 1949 | + if (/chrome/.test(navigator.userAgent)) { |
| 1950 | + it('should support assigning bindings to class-based controller', function() { |
| 1951 | + var called = false; |
| 1952 | + var data = [ |
| 1953 | + { name: 'derp1', id: 0 }, |
| 1954 | + { name: 'testname', id: 1 }, |
| 1955 | + { name: 'flurp', id: 2 } |
| 1956 | + ]; |
| 1957 | + module(function($controllerProvider) { |
| 1958 | + //jshint evil: true |
| 1959 | + var TestCtrl = eval('(class { constructor() { called = true; } })'); |
| 1960 | + //jshint evil: false |
| 1961 | + $controllerProvider.register('testCtrl', TestCtrl); |
| 1962 | + }); |
| 1963 | + inject(function($controller, $rootScope) { |
| 1964 | + var ctrl = $controller('testCtrl', { scope: $rootScope }, { data: data }); |
| 1965 | + expect(ctrl.data).toBe(data); |
| 1966 | + expect(called).toBe(true); |
| 1967 | + }); |
| 1968 | + }); |
| 1969 | + } |
1922 | 1970 | });
|
1923 | 1971 |
|
1924 | 1972 |
|
|
0 commit comments