Skip to content

Commit 80d90da

Browse files
committed
Merge pull request angular-ui#58 from duncanbeevers/spec-error-cases
Add specs for error cases
2 parents 8b3d1bb + 2bca216 commit 80d90da

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/select.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ angular.module('ui.select', [])
5555
* keyIdentifier = undefined
5656
*/
5757
self.parse = function(expression) {
58+
if (!expression) {
59+
throw uiSelectMinErr('repeat', "Expected 'repeat' expression.");
60+
}
61+
5862
var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
5963

6064
if (!match) {

test/select.spec.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,33 @@ describe('ui-select tests', function() {
182182
expect(el.scope().$select.selected).toEqual('false');
183183
expect(getMatchLabel(el)).toEqual('false');
184184
});
185-
});
185+
186+
it('should throw when no ui-select-choices found', function() {
187+
expect(function() {
188+
compileTemplate(
189+
'<ui-select ng-model="selection"> \
190+
<ui-select-match></ui-select-match> \
191+
</ui-select>'
192+
);
193+
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-choices but got \'0\'.'));
194+
});
195+
196+
it('should throw when no repeat attribute is provided to ui-select-choices', function() {
197+
expect(function() {
198+
compileTemplate(
199+
'<ui-select ng-model="selection"> \
200+
<ui-select-choices></ui-select-choices> \
201+
</ui-select>'
202+
);
203+
}).toThrow(new Error('[ui.select:repeat] Expected \'repeat\' expression.'));
204+
});
205+
206+
it('should throw when no ui-select-match found', function() {
207+
expect(function() {
208+
compileTemplate(
209+
'<ui-select ng-model="selection"> \
210+
<ui-select-choices repeat="item in items"></ui-select-choices> \
211+
</ui-select>'
212+
);
213+
}).toThrow(new Error('[ui.select:transcluded] Expected 1 .ui-select-match but got \'0\'.'));
214+
});});

0 commit comments

Comments
 (0)