Skip to content

Commit ff596e6

Browse files
committed
Added a few more tests
This adds a test that makes sure that the inline data attribute overrides the options that are passed in during initialization. This also adds a test for the `createTag` option, which is used when tagging.
1 parent 6a5127a commit ff596e6

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

tests/data/tags-tests.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var options = new Options({
1212
tags: true
1313
});
1414

15-
test('does not trigger on blank/null terms', function (assert) {
15+
test('does not trigger on blank or null terms', function (assert) {
1616
var data = new SelectTags($('#qunit-fixture .single'), options);
1717

1818
data.query({
@@ -185,3 +185,31 @@ test('createTag returns null for no tag', function (assert) {
185185
assert.equal(data.results.length, 1);
186186
});
187187
});
188+
189+
test('the createTag options customizes the function', function (assert) {
190+
var data = new SelectTags(
191+
$('#qunit-fixture .single'),
192+
new Options({
193+
tags: true,
194+
createTag: function (params) {
195+
return {
196+
id: params.term,
197+
text: params.term,
198+
tag: true
199+
};
200+
}
201+
})
202+
);
203+
204+
data.query({
205+
term: 'test'
206+
}, function (data) {
207+
assert.equal(data.results.length, 1);
208+
209+
var item = data.results[0];
210+
211+
assert.equal(item.id, 'test');
212+
assert.equal(item.text, 'test');
213+
assert.equal(item.tag, true);
214+
});
215+
});

tests/options/data-tests.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ test('with nesting', function (assert) {
1818
assert.ok(!(options.get('first-Second')));
1919
assert.equal(options.get('first').second, 'test');
2020
});
21+
22+
test('overrides initialized data', function (assert) {
23+
var $test = $('<select data-override="yes" data-data="yes"></select>');
24+
25+
var options = new Options({
26+
options: 'yes',
27+
override: 'no'
28+
}, $test);
29+
30+
assert.equal(options.get('options'), 'yes');
31+
assert.equal(options.get('override'), 'yes');
32+
assert.equal(options.get('data'), 'yes');
33+
});

0 commit comments

Comments
 (0)