Skip to content

Commit b34716e

Browse files
committed
fix(spec): Use exceptionHandler to test errors.
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 7aabdc4 commit b34716e

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

test/select.spec.js

Lines changed: 41 additions & 36 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

@@ -1110,45 +1111,49 @@ describe('ui-select tests', function() {
11101111

11111112

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

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

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

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

11541159
it('should format the model correctly using alias', function() {
@@ -3107,7 +3112,7 @@ describe('ui-select tests', function() {
31073112

31083113
describe('Test Spinner for promises',function(){
31093114
var deferred;
3110-
3115+
31113116
function getFromServer(){
31123117
deferred = $q.defer();
31133118
return deferred.promise;
@@ -3130,14 +3135,14 @@ describe('ui-select tests', function() {
31303135
it('should have set a custom class value of randomclass', function () {
31313136
var control = createUiSelect({spinnerClass: 'randomclass'});
31323137
expect(control.scope().$select.spinnerClass).toEqual('randomclass');
3133-
});
3138+
});
31343139

31353140
it('should not display spinner when disabled', function() {
31363141
scope.getFromServer = getFromServer;
31373142
var el = createUiSelect({theme: 'bootstrap', refresh:"getFromServer($select.search)", refreshDelay:0});
31383143
openDropdown(el);
31393144
var spinner = el.find('.ui-select-refreshing');
3140-
expect(spinner.hasClass('ng-hide')).toBe(true);
3145+
expect(spinner.hasClass('ng-hide')).toBe(true);
31413146
setSearchText(el, 'a');
31423147
expect(spinner.hasClass('ng-hide')).toBe(true);
31433148
deferred.resolve();
@@ -3150,7 +3155,7 @@ describe('ui-select tests', function() {
31503155
var el = createUiSelect({spinnerEnabled: true,theme: 'bootstrap', refresh:"getFromServer($select.search)", refreshDelay:0});
31513156
openDropdown(el);
31523157
var spinner = el.find('.ui-select-refreshing');
3153-
expect(spinner.hasClass('ng-hide')).toBe(true);
3158+
expect(spinner.hasClass('ng-hide')).toBe(true);
31543159
setSearchText(el, 'a');
31553160
expect(spinner.hasClass('ng-hide')).toBe(false);
31563161
deferred.resolve();

0 commit comments

Comments
 (0)