Skip to content

Commit a9863bf

Browse files
committed
test($injector): fix incorrect test and error message assertions
Fix a test that was never run. Ensure the assertions for `$injector:cdep`/`$injector:unpr` errors test the whole path.
1 parent 2e0441d commit a9863bf

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

test/auto/injectorSpec.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ describe('injector', function() {
8080
it('should provide useful message if no provider', function() {
8181
expect(function() {
8282
injector.get('idontexist');
83-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: idontexistProvider <- idontexist");
83+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: idontexistProvider <- idontexist\n');
8484
});
8585

8686

8787
it('should provide the caller name if given', function() {
8888
expect(function() {
8989
injector.get('idontexist', 'callerName');
90-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: idontexistProvider <- idontexist <- callerName");
90+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: idontexistProvider <- idontexist <- callerName\n');
9191
});
9292

9393

@@ -96,18 +96,18 @@ describe('injector', function() {
9696
var $controller = injector.get('$controller');
9797
expect(function() {
9898
$controller('myCtrl', {$scope: {}});
99-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: idontexistProvider <- idontexist <- myCtrl");
99+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: idontexistProvider <- idontexist <- myCtrl\n');
100100
});
101101

102102

103103
it('should not corrupt the cache when an object fails to get instantiated', function() {
104104
expect(function() {
105105
injector.get('idontexist');
106-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: idontexistProvider <- idontexist");
106+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: idontexistProvider <- idontexist\n');
107107

108108
expect(function() {
109109
injector.get('idontexist');
110-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: idontexistProvider <- idontexist");
110+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: idontexistProvider <- idontexist\n');
111111
});
112112

113113

@@ -116,7 +116,7 @@ describe('injector', function() {
116116
providers('b', function(a) {return 2;});
117117
expect(function() {
118118
injector.get('b');
119-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: idontexistProvider <- idontexist <- a <- b");
119+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: idontexistProvider <- idontexist <- a <- b\n');
120120
});
121121

122122

@@ -800,7 +800,7 @@ describe('injector', function() {
800800
expect(function() {
801801
createInjector(['TestModule']);
802802
}).toThrowMinErr(
803-
'$injector', 'modulerr', /Failed to instantiate module TestModule due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/
803+
'$injector', 'modulerr', /Failed to instantiate module TestModule due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy\n/
804804
);
805805
});
806806

@@ -810,7 +810,7 @@ describe('injector', function() {
810810
expect(function() {
811811
createInjector([myModule]);
812812
}).toThrowMinErr(
813-
'$injector', 'modulerr', /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/
813+
'$injector', 'modulerr', /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy\n/
814814
);
815815
});
816816

@@ -820,7 +820,7 @@ describe('injector', function() {
820820
expect(function() {
821821
createInjector([['xyzzy', myModule]]);
822822
}).toThrowMinErr(
823-
'$injector', 'modulerr', /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy/
823+
'$injector', 'modulerr', /Failed to instantiate module function myModule\(xyzzy\) due to:\n.*\[\$injector:unpr] Unknown provider: xyzzy\n/
824824
);
825825
});
826826

@@ -831,7 +831,7 @@ describe('injector', function() {
831831
$provide.factory('service', function(service) {});
832832
return function(service) {};
833833
}]);
834-
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service <- service');
834+
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: service <- service\n');
835835
});
836836

837837

@@ -842,7 +842,7 @@ describe('injector', function() {
842842
$provide.factory('b', function(a) {});
843843
return function(a) {};
844844
}]);
845-
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: a <- b <- a');
845+
}).toThrowMinErr('$injector', 'cdep', 'Circular dependency found: a <- b <- a\n');
846846
});
847847

848848
});
@@ -1043,15 +1043,15 @@ describe('injector', function() {
10431043
}]);
10441044
expect(function() {
10451045
$injector.get('nameProvider');
1046-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: nameProviderProvider <- nameProvider");
1046+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: nameProviderProvider <- nameProvider\n');
10471047
});
10481048

10491049

10501050
it('should prevent provider configuration in app', function() {
10511051
var $injector = createInjector([]);
10521052
expect(function() {
10531053
$injector.get('$provide').value('a', 'b');
1054-
}).toThrowMinErr("$injector", "unpr", "Unknown provider: $provideProvider <- $provide");
1054+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: $provideProvider <- $provide\n');
10551055
});
10561056

10571057

@@ -1061,7 +1061,7 @@ describe('injector', function() {
10611061
createInjector([function($provide) {
10621062
$provide.value('name', 'angular');
10631063
}, instanceLookupInModule]);
1064-
}).toThrowError(/\[\$injector:unpr] Unknown provider: name/);
1064+
}).toThrowError(/\[\$injector:unpr] Unknown provider: name\n/);
10651065
});
10661066
});
10671067
});
@@ -1071,11 +1071,18 @@ describe('strict-di injector', function() {
10711071

10721072
describe('with ngMock', function() {
10731073
it('should not throw when calling mock.module() with "magic" annotations', function() {
1074+
var executed = false;
1075+
10741076
expect(function() {
10751077
module(function($provide, $httpProvider, $compileProvider) {
10761078
// Don't throw!
1079+
executed = true;
10771080
});
10781081
}).not.toThrow();
1082+
1083+
inject();
1084+
1085+
expect(executed).toBe(true);
10791086
});
10801087

10811088

test/ng/parseSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,7 @@ describe('parser', function() {
19941994

19951995
expect(function() {
19961996
scope.$eval("1|nonexistent");
1997-
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: nonexistentFilterProvider <- nonexistentFilter');
1997+
}).toThrowMinErr('$injector', 'unpr', 'Unknown provider: nonexistentFilterProvider <- nonexistentFilter\n');
19981998

19991999
scope.offset = 3;
20002000
expect(scope.$eval("'abcd'|substring:1:offset")).toEqual("bc");

0 commit comments

Comments
 (0)