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

set default value to empty array #251

Merged
merged 2 commits into from
Mar 16, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/uiSelectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ uis.controller('uiSelectCtrl',
}

function setPlainItems(items) {
ctrl.items = items;
ctrl.items = items || [];
}

ctrl.setItemsFn = groupByExp ? updateGroups : setPlainItems;
Expand Down
21 changes: 18 additions & 3 deletions test/select.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ describe('ui-select tests', function() {
scope.$digest();
}

it('should initialize selected choices with an array if choices source is undefined', function(){
var el = createUiSelect(),
ctrl = el.scope().$select;

ctrl.setItemsFn(); // setPlainItems
expect(ctrl.items).toEqual([]);
});

// Tests
//uisRepeatParser
Expand Down Expand Up @@ -1864,6 +1871,14 @@ describe('ui-select tests', function() {
);
}

it('should initialize selected choices with an empty array when choices source is undefined', function(){
var el = createUiSelectMultiple({groupBy: "'age'"}),
ctrl = el.scope().$select;

ctrl.setItemsFn(); // updateGroups
expect(ctrl.items).toEqual([]);
});

it('should render initial state', function() {
var el = createUiSelectMultiple();
expect(el).toHaveClass('ui-select-multiple');
Expand Down Expand Up @@ -3231,12 +3246,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 +3263,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