Skip to content

Commit b549db9

Browse files
pete-otaquiaaronroberson
authored andcommitted
fix(spec): Use exceptionHandler to test errors. (angular-ui#1879)
Angular 1.6 alters the way uncaught promises are handled - errors cause promise rejection rather than outright exceptions to be thrown. Update existing exception tests to use the exceptionHandler service instead of `.throws()` Closes angular-ui#1877
1 parent 531e4b3 commit b549db9

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

test/select.spec.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
describe('ui-select tests', function() {
4-
var scope, $rootScope, $compile, $timeout, $injector, $q,uisRepeatParser ;
4+
var scope, $rootScope, $compile, $timeout, $injector, $q,uisRepeatParser, $exceptionHandler;
55

66
var Key = {
77
Enter: 13,
@@ -78,13 +78,14 @@ describe('ui-select tests', function() {
7878
});
7979
});
8080

81-
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_,_$q_ , _uisRepeatParser_) {
81+
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_,_$q_ , _uisRepeatParser_, _$exceptionHandler_) {
8282
$rootScope = _$rootScope_;
8383
scope = $rootScope.$new();
8484
$compile = _$compile_;
8585
$timeout = _$timeout_;
8686
$injector = _$injector_;
8787
$q = _$q_;
88+
$exceptionHandler = _$exceptionHandler_;
8889
uisRepeatParser = _uisRepeatParser_;
8990
scope.selection = {};
9091

@@ -1112,45 +1113,49 @@ describe('ui-select tests', function() {
11121113

11131114

11141115
it('should throw when no ui-select-choices found', function() {
1115-
expect(function() {
1116-
compileTemplate(
1117-
'<ui-select ng-model="selection.selected"> \
1118-
<ui-select-match></ui-select-match> \
1119-
</ui-select>'
1120-
);
1121-
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-choices but got \'0\'.'));
1116+
compileTemplate(
1117+
'<ui-select ng-model="selection.selected"> \
1118+
<ui-select-match></ui-select-match> \
1119+
</ui-select>'
1120+
);
1121+
var lastError = $exceptionHandler.errors[$exceptionHandler.errors.length-1];
1122+
var expectedError = new Error('[ui.select:transcluded] Expected 1 .ui-select-choices but got \'0\'.');
1123+
expect(lastError).toEqual(expectedError);
11221124
});
11231125

11241126
it('should throw when no repeat attribute is provided to ui-select-choices', function() {
1125-
expect(function() {
1126-
compileTemplate(
1127-
'<ui-select ng-model="selection.selected"> \
1128-
<ui-select-match></ui-select-match> \
1129-
<ui-select-choices></ui-select-choices> \
1130-
</ui-select>'
1131-
);
1132-
}).toThrow(new Error('[ui.select:repeat] Expected \'repeat\' expression.'));
1127+
compileTemplate(
1128+
'<ui-select ng-model="selection.selected"> \
1129+
<ui-select-match></ui-select-match> \
1130+
<ui-select-choices></ui-select-choices> \
1131+
</ui-select>'
1132+
);
1133+
var lastError = $exceptionHandler.errors[$exceptionHandler.errors.length-1];
1134+
var expectedError = new Error('[ui.select:repeat] Expected \'repeat\' expression.');
1135+
expect(lastError).toEqual(expectedError);
11331136
});
11341137

11351138
it('should throw when repeat attribute has incorrect format ', function() {
1136-
expect(function() {
1137-
compileTemplate(
1138-
'<ui-select ng-model="selection.selected"> \
1139-
<ui-select-match></ui-select-match> \
1140-
<ui-select-choices repeat="incorrect format people"></ui-select-choices> \
1141-
</ui-select>'
1142-
);
1143-
}).toThrow(new Error('[ui.select:iexp] Expected expression in form of \'_item_ in _collection_[ track by _id_]\' but got \'incorrect format people\'.'));
1139+
compileTemplate(
1140+
'<ui-select ng-model="selection.selected"> \
1141+
<ui-select-match></ui-select-match> \
1142+
<ui-select-choices repeat="incorrect format people"></ui-select-choices> \
1143+
</ui-select>'
1144+
);
1145+
var lastError = $exceptionHandler.errors[$exceptionHandler.errors.length-1];
1146+
var expectedError = new Error('[ui.select:iexp] Expected expression in form of \'_item_ in _collection_[ track by _id_]\' but got \'incorrect format people\'.');
1147+
expect(lastError).toEqual(expectedError);
11441148
});
11451149

11461150
it('should throw when no ui-select-match found', function() {
1147-
expect(function() {
1148-
compileTemplate(
1149-
'<ui-select ng-model="selection.selected"> \
1150-
<ui-select-choices repeat="item in items"></ui-select-choices> \
1151-
</ui-select>'
1152-
);
1153-
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.'));
1151+
compileTemplate(
1152+
'<ui-select ng-model="selection.selected"> \
1153+
<ui-select-choices repeat="item in items"></ui-select-choices> \
1154+
</ui-select>'
1155+
);
1156+
var lastError = $exceptionHandler.errors[$exceptionHandler.errors.length-1];
1157+
var expectedError = new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.');
1158+
expect(lastError).toEqual(expectedError);
11541159
});
11551160

11561161
it('should format the model correctly using alias', function() {

0 commit comments

Comments
 (0)