Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
fix(spec): Use exceptionHandler to test errors. (#1879)
Browse files Browse the repository at this point in the history
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 #1877
  • Loading branch information
pete-otaqui authored and aaronroberson committed Jan 4, 2017
1 parent 531e4b3 commit b549db9
Showing 1 changed file with 37 additions and 32 deletions.
69 changes: 37 additions & 32 deletions test/select.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

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

var Key = {
Enter: 13,
Expand Down Expand Up @@ -78,13 +78,14 @@ describe('ui-select tests', function() {
});
});

beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_,_$q_ , _uisRepeatParser_) {
beforeEach(inject(function(_$rootScope_, _$compile_, _$timeout_, _$injector_,_$q_ , _uisRepeatParser_, _$exceptionHandler_) {
$rootScope = _$rootScope_;
scope = $rootScope.$new();
$compile = _$compile_;
$timeout = _$timeout_;
$injector = _$injector_;
$q = _$q_;
$exceptionHandler = _$exceptionHandler_;
uisRepeatParser = _uisRepeatParser_;
scope.selection = {};

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


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

it('should throw when no repeat attribute is provided to ui-select-choices', function() {
expect(function() {
compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match></ui-select-match> \
<ui-select-choices></ui-select-choices> \
</ui-select>'
);
}).toThrow(new Error('[ui.select:repeat] Expected \'repeat\' expression.'));
compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-match></ui-select-match> \
<ui-select-choices></ui-select-choices> \
</ui-select>'
);
var lastError = $exceptionHandler.errors[$exceptionHandler.errors.length-1];
var expectedError = new Error('[ui.select:repeat] Expected \'repeat\' expression.');
expect(lastError).toEqual(expectedError);
});

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

it('should throw when no ui-select-match found', function() {
expect(function() {
compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-choices repeat="item in items"></ui-select-choices> \
</ui-select>'
);
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.'));
compileTemplate(
'<ui-select ng-model="selection.selected"> \
<ui-select-choices repeat="item in items"></ui-select-choices> \
</ui-select>'
);
var lastError = $exceptionHandler.errors[$exceptionHandler.errors.length-1];
var expectedError = new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.');
expect(lastError).toEqual(expectedError);
});

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

0 comments on commit b549db9

Please sign in to comment.