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

Commit 7800e65

Browse files
committed
Add test for null/undefined values
1 parent b787159 commit 7800e65

File tree

1 file changed

+54
-16
lines changed

1 file changed

+54
-16
lines changed

Diff for: test/select.spec.js

+54-16
Original file line numberDiff line numberDiff line change
@@ -1610,42 +1610,42 @@ describe('ui-select tests', function() {
16101610
expect(el.find('.ui-select-match-item').length).toBe(0);
16111611
});
16121612

1613-
it('should render intial state with data-multiple attribute', function () {
1614-
// ensure match template has been loaded by having more than one selection
1615-
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];
1616-
1613+
it('should render intial state with data-multiple attribute', function () {
1614+
// ensure match template has been loaded by having more than one selection
1615+
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];
1616+
16171617
var el = compileTemplate(
16181618
'<ui-select data-multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
16191619
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
16201620
<ui-select-choices repeat="person in people | filter: $select.search"> \
16211621
<div ng-bind-html="person.name | highlight: $select.search"></div> \
16221622
<div ng-bind-html="person.email | highlight: $select.search"></div> \
16231623
</ui-select-choices> \
1624-
</ui-select>'
1625-
);
1626-
1624+
</ui-select>'
1625+
);
1626+
16271627
expect(el).toHaveClass('ui-select-multiple');
16281628
expect(el.scope().$select.selected.length).toBe(2);
1629-
expect(el.find('.ui-select-match-item').length).toBe(2);
1629+
expect(el.find('.ui-select-match-item').length).toBe(2);
16301630
});
16311631

1632-
it('should render intial state with x-multiple attribute', function () {
1633-
// ensure match template has been loaded by having more than one selection
1634-
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];
1635-
1632+
it('should render intial state with x-multiple attribute', function () {
1633+
// ensure match template has been loaded by having more than one selection
1634+
scope.selection.selectedMultiple = [scope.people[0], scope.people[1]];
1635+
16361636
var el = compileTemplate(
16371637
'<ui-select x-multiple ng-model="selection.selectedMultiple" theme="bootstrap" style="width: 800px;"> \
16381638
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
16391639
<ui-select-choices repeat="person in people | filter: $select.search"> \
16401640
<div ng-bind-html="person.name | highlight: $select.search"></div> \
16411641
<div ng-bind-html="person.email | highlight: $select.search"></div> \
16421642
</ui-select-choices> \
1643-
</ui-select>'
1644-
);
1645-
1643+
</ui-select>'
1644+
);
1645+
16461646
expect(el).toHaveClass('ui-select-multiple');
16471647
expect(el.scope().$select.selected.length).toBe(2);
1648-
expect(el.find('.ui-select-match-item').length).toBe(2);
1648+
expect(el.find('.ui-select-match-item').length).toBe(2);
16491649
});
16501650

16511651
it('should set model as an empty array if ngModel isnt defined after an item is selected', function () {
@@ -2206,6 +2206,44 @@ describe('ui-select tests', function() {
22062206
expect(el.scope().$select.multiple).toBe(true);
22072207
});
22082208

2209+
it('should have tolerance for undefined values', function () {
2210+
2211+
scope.modelValue = undefined;
2212+
2213+
var el = compileTemplate(
2214+
'<ui-select multiple ng-model="modelValue" theme="bootstrap" style="width: 800px;"> \
2215+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
2216+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
2217+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
2218+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
2219+
</ui-select-choices> \
2220+
</ui-select> \
2221+
'
2222+
);
2223+
2224+
expect($(el).scope().$select.selected).toEqual([]);
2225+
2226+
});
2227+
2228+
it('should have tolerance for null values', function () {
2229+
2230+
scope.modelValue = null;
2231+
2232+
var el = compileTemplate(
2233+
'<ui-select multiple ng-model="modelValue" theme="bootstrap" style="width: 800px;"> \
2234+
<ui-select-match placeholder="Pick one...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match> \
2235+
<ui-select-choices repeat="person.email as person in people | filter: $select.search"> \
2236+
<div ng-bind-html="person.name | highlight: $select.search"></div> \
2237+
<div ng-bind-html="person.email | highlight: $select.search"></div> \
2238+
</ui-select-choices> \
2239+
</ui-select> \
2240+
'
2241+
);
2242+
2243+
expect($(el).scope().$select.selected).toEqual([]);
2244+
2245+
});
2246+
22092247
it('should allow paste tag from clipboard', function() {
22102248
scope.taggingFunc = function (name) {
22112249
return {

0 commit comments

Comments
 (0)