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

fix(unit tests) Changes for angular 1.5+ #1917

Merged
merged 1 commit into from
Feb 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 5 additions & 53 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, $exceptionHandler;
var scope, $rootScope, $compile, $timeout, $injector, $q,uisRepeatParser;

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

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

Expand Down Expand Up @@ -1111,53 +1110,6 @@ describe('ui-select tests', function() {
});
});


it('should throw when no ui-select-choices found', function() {
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() {
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() {
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() {
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() {
var el = compileTemplate(
'<ui-select ng-model="selection.selected"> \
Expand Down Expand Up @@ -3231,12 +3183,12 @@ describe('ui-select tests', function() {
expect(el.scope().$select.spinnerClass).toBe('randomclass');
});
});

describe('With refresh on active', function(){
it('should refresh when is activated', function(){
scope.fetchFromServer = function(){};
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
spyOn(scope, 'fetchFromServer');
spyOn(scope, 'fetchFromServer');
expect(el.scope().$select.open).toEqual(false);
el.scope().$select.activate();
$timeout.flush();
Expand All @@ -3248,7 +3200,7 @@ describe('ui-select tests', function() {
it('should refresh when open is set to true', function(){
scope.fetchFromServer = function(){};
var el = createUiSelect({refresh:"fetchFromServer($select.search)",refreshDelay:0});
spyOn(scope, 'fetchFromServer');
spyOn(scope, 'fetchFromServer');
expect(el.scope().$select.open).toEqual(false);
openDropdown(el);
$timeout.flush();
Expand Down