|
3 | 3 | describe('API', function() {
|
4 | 4 |
|
5 | 5 | describe('disable()', function() {
|
| 6 | + var test; |
| 7 | + |
6 | 8 | before(function() {
|
7 | 9 | test = setup_test('<select>', {});
|
8 | 10 | test.selectize.disable();
|
9 | 11 | });
|
10 |
| - after(function() { |
11 |
| - test.teardown(); |
12 |
| - }); |
13 | 12 | it('should set "disabled" class', function() {
|
14 | 13 | expect(test.selectize.$control.hasClass('disabled')).to.be.equal(true);
|
15 | 14 | });
|
|
22 | 21 | });
|
23 | 22 |
|
24 | 23 | describe('enable()', function() {
|
| 24 | + var test; |
| 25 | + |
25 | 26 | before(function() {
|
26 | 27 | test = setup_test('<select disabled>', {});
|
27 | 28 | test.selectize.enable();
|
28 | 29 | });
|
29 |
| - after(function() { |
30 |
| - test.teardown(); |
31 |
| - }); |
32 | 30 | it('should remove "disabled" class', function() {
|
33 | 31 | expect(test.selectize.$control.hasClass('disabled')).to.be.equal(false);
|
34 | 32 | });
|
|
41 | 39 | });
|
42 | 40 |
|
43 | 41 | describe('focus()', function() {
|
44 |
| - before(function(done) { |
45 |
| - test = setup_test('<select>', {}); |
| 42 | + it('should set isFocused property to true', function(done) { |
| 43 | + var test = setup_test('<select>', {}); |
46 | 44 | test.selectize.focus();
|
47 |
| - window.setTimeout(done, 5); |
48 |
| - }); |
49 |
| - after(function() { |
50 |
| - test.teardown(); |
51 |
| - }); |
52 |
| - it('should set isFocused property to true', function() { |
53 |
| - expect(test.selectize.isFocused).to.be.equal(true); |
| 45 | + window.setTimeout(function() { |
| 46 | + expect(test.selectize.isFocused).to.be.equal(true); |
| 47 | + done(); |
| 48 | + }, 5); |
54 | 49 | });
|
55 |
| - it('should give the control focus', function() { |
56 |
| - expect(has_focus(test.selectize.$control_input[0])).to.be.equal(true); |
| 50 | + it('should give the control focus', function(done) { |
| 51 | + var test = setup_test('<select>', {}); |
| 52 | + test.selectize.focus(); |
| 53 | + window.setTimeout(function() { |
| 54 | + expect(has_focus(test.selectize.$control_input[0])).to.be.equal(true); |
| 55 | + done(); |
| 56 | + }, 5); |
57 | 57 | });
|
58 | 58 | });
|
59 | 59 |
|
60 | 60 | describe('blur()', function() {
|
| 61 | + var test; |
| 62 | + |
61 | 63 | before(function(done) {
|
62 | 64 | test = setup_test('<select>', {});
|
63 | 65 | test.selectize.focus();
|
|
66 | 68 | window.setTimeout(done, 5);
|
67 | 69 | }, 5);
|
68 | 70 | });
|
69 |
| - after(function() { |
70 |
| - test.teardown(); |
71 |
| - }); |
72 | 71 | it('should set isFocused property to false', function() {
|
73 | 72 | expect(test.selectize.isFocused).to.be.equal(false);
|
74 | 73 | });
|
|
79 | 78 |
|
80 | 79 | describe('createItem()', function() {
|
81 | 80 | it('should fail if non-object returned by "create" callback', function() {
|
82 |
| - test = setup_test('<select>', { |
| 81 | + var test = setup_test('<select>', { |
83 | 82 | valueField: 'value',
|
84 | 83 | labelField: 'value',
|
85 | 84 | create: function(input) {
|
|
90 | 89 | test.selectize.$control_input.val('test');
|
91 | 90 | test.selectize.createItem();
|
92 | 91 | expect(test.selectize.items.length).to.be.equal(0);
|
93 |
| - test.teardown(); |
94 | 92 |
|
95 | 93 | test = setup_test('<select>', {
|
96 | 94 | valueField: 'value',
|
|
103 | 101 | test.selectize.$control_input.val('test');
|
104 | 102 | test.selectize.createItem();
|
105 | 103 | expect(test.selectize.items.length).to.be.equal(0);
|
106 |
| - test.teardown(); |
107 | 104 | });
|
108 | 105 | it('should add option upon completion (synchronous)', function() {
|
109 |
| - test = setup_test('<select>', { |
| 106 | + var test = setup_test('<select>', { |
110 | 107 | valueField: 'value',
|
111 | 108 | labelField: 'value',
|
112 | 109 | create: function(input) {
|
|
117 | 114 | test.selectize.$control_input.val('test');
|
118 | 115 | test.selectize.createItem();
|
119 | 116 | expect(test.selectize.options).to.have.property('test');
|
120 |
| - test.teardown(); |
121 | 117 | });
|
122 | 118 | it('should add option upon completion (asynchronous)', function(done) {
|
123 |
| - test = setup_test('<select>', { |
| 119 | + var test = setup_test('<select>', { |
124 | 120 | valueField: 'value',
|
125 | 121 | labelField: 'value',
|
126 | 122 | create: function(input, callback) {
|
127 | 123 | window.setTimeout(function() {
|
128 | 124 | callback({value: input});
|
129 | 125 | expect(test.selectize.options).to.have.property('test');
|
130 |
| - test.teardown(); |
131 | 126 | done();
|
132 | 127 | }, 0);
|
133 | 128 | }
|
|
139 | 134 | });
|
140 | 135 |
|
141 | 136 | describe('addOptionGroup()', function() {
|
| 137 | + var test; |
| 138 | + |
142 | 139 | before(function() {
|
143 | 140 | test = setup_test('<select>', {valueField: 'value', labelField: 'value'});
|
144 | 141 | });
|
145 |
| - after(function() { |
146 |
| - test.teardown(); |
147 |
| - }); |
148 | 142 | it('should register group', function() {
|
149 | 143 | var data = {label: 'Group Label'};
|
150 | 144 | test.selectize.addOptionGroup('group_id', data);
|
|
154 | 148 | });
|
155 | 149 |
|
156 | 150 | describe('addOption()', function() {
|
| 151 | + var test; |
| 152 | + |
157 | 153 | before(function() {
|
158 | 154 | test = setup_test('<select>', {valueField: 'value', labelField: 'value'});
|
159 | 155 | });
|
160 |
| - after(function() { |
161 |
| - test.teardown(); |
162 |
| - }); |
163 | 156 | it('should allow string values', function() {
|
164 | 157 | test.selectize.addOption({value: 'stringtest'});
|
165 | 158 | expect(test.selectize.options).to.have.property('stringtest');
|
|
190 | 183 | });
|
191 | 184 |
|
192 | 185 | describe('addItem()', function() {
|
| 186 | + var test; |
| 187 | + |
193 | 188 | before(function() {
|
194 | 189 | test = setup_test('<select multiple>', {
|
195 | 190 | valueField: 'value',
|
|
209 | 204 | ]
|
210 | 205 | });
|
211 | 206 | });
|
212 |
| - after(function() { |
213 |
| - test.teardown(); |
214 |
| - }); |
215 | 207 | it('should update "items" array', function() {
|
216 | 208 | test.selectize.addItem('b');
|
217 | 209 | expect(test.selectize.items.indexOf('b')).to.be.equal(0);
|
|
245 | 237 | });
|
246 | 238 |
|
247 | 239 | describe('updateOption()', function() {
|
| 240 | + var test; |
| 241 | + |
248 | 242 | before(function() {
|
249 | 243 | test = setup_test('<select multiple>', {
|
250 | 244 | valueField: 'value',
|
|
268 | 262 | items: ['e','f']
|
269 | 263 | });
|
270 | 264 | });
|
271 |
| - after(function() { |
272 |
| - test.teardown(); |
273 |
| - }); |
274 | 265 | it('should update option data', function() {
|
275 | 266 | test.selectize.updateOption('a', {value: 'a', test: 'test'});
|
276 | 267 | expect(test.selectize.options).to.have.property('a');
|
|
311 | 302 | });
|
312 | 303 |
|
313 | 304 | describe('getOption()', function() {
|
| 305 | + var test; |
| 306 | + |
314 | 307 | before(function() {
|
315 | 308 | test = setup_test('<select>', {
|
316 | 309 | valueField: 'value',
|
|
329 | 322 | });
|
330 | 323 | test.selectize.refreshOptions(true);
|
331 | 324 | });
|
332 |
| - after(function() { |
333 |
| - test.teardown(); |
334 |
| - }); |
335 | 325 | it('should allow string values', function() {
|
336 | 326 | expect(test.selectize.getOption('a')).to.be.ok;
|
337 | 327 | expect(test.selectize.getOption('a').length).to.be.equal(1);
|
|
367 | 357 | });
|
368 | 358 |
|
369 | 359 | describe('getItem()', function() {
|
| 360 | + var test; |
| 361 | + |
370 | 362 | before(function() {
|
371 | 363 | test = setup_test('<select multiple>', {
|
372 | 364 | valueField: 'value',
|
|
379 | 371 | {value: '\''},
|
380 | 372 | {value: '"'},
|
381 | 373 | {value: '\\\''},
|
382 |
| - {value: '\\"'}, |
| 374 | + {value: '\\"'} |
383 | 375 | ],
|
384 | 376 | items: ['0','1','a','b','\'','"','\\\'','\\"']
|
385 | 377 | });
|
386 | 378 | });
|
387 |
| - after(function() { |
388 |
| - test.teardown(); |
389 |
| - }); |
390 | 379 | it('should allow string values', function() {
|
391 | 380 | expect(test.selectize.getItem('a')).to.be.ok;
|
392 | 381 | expect(test.selectize.getItem('a').length).to.be.equal(1);
|
|
420 | 409 | });
|
421 | 410 |
|
422 | 411 | describe('clear()', function() {
|
| 412 | + var test; |
| 413 | + |
423 | 414 | before(function() {
|
424 | 415 | test = setup_test('<select multiple>', {
|
425 | 416 | valueField: 'value',
|
|
433 | 424 | items: ['1','2','3']
|
434 | 425 | });
|
435 | 426 | });
|
436 |
| - after(function() { |
437 |
| - test.teardown(); |
438 |
| - }); |
439 | 427 | it('should empty "items" array', function() {
|
440 | 428 | test.selectize.clear();
|
441 | 429 | expect(test.selectize.items.length).to.be.equal(0);
|
|
457 | 445 |
|
458 | 446 | describe('search()', function() {
|
459 | 447 | it('should throw error if "score" setting does not return a function', function() {
|
| 448 | + var test; |
| 449 | + |
460 | 450 | expect(function() {
|
461 | 451 | test = setup_test('<select multiple>', {
|
462 | 452 | valueField: 'value',
|
|
469 | 459 | });
|
470 | 460 | test.selectize.search('hello');
|
471 | 461 | }).to.throw(Error);
|
472 |
| - test.teardown(); |
473 | 462 | });
|
474 | 463 | it('should not throw error if "score" setting does return a function', function() {
|
| 464 | + var test; |
| 465 | + |
475 | 466 | expect(function() {
|
476 | 467 | test = setup_test('<select multiple>', {
|
477 | 468 | valueField: 'value',
|
|
486 | 477 | });
|
487 | 478 | test.selectize.search('hello');
|
488 | 479 | }).to.not.throw(Error);
|
489 |
| - test.teardown(); |
490 | 480 | });
|
491 | 481 | });
|
492 | 482 |
|
493 | 483 | describe('getScoreFunction()', function() {
|
494 | 484 | it('should return an function that returns a number', function() {
|
495 |
| - test = setup_test('<select multiple>', { |
| 485 | + var test = setup_test('<select multiple>', { |
496 | 486 | valueField: 'value',
|
497 | 487 | labelField: 'value',
|
498 | 488 | searchField: 'value',
|
|
523 | 513 | return false;
|
524 | 514 | };
|
525 | 515 | it('should remove control from DOM', function() {
|
526 |
| - test = setup_test('<select>', {}); |
| 516 | + var test = setup_test('<select>', {}); |
527 | 517 | test.selectize.destroy();
|
528 | 518 | expect($.contains(document.documentElement, test.selectize.$wrapper[0])).to.be.equal(false);
|
529 |
| - test.teardown(); |
530 | 519 | });
|
531 | 520 | it('should delete "selectize" reference on original input element', function() {
|
532 |
| - test = setup_test('<select>', {}); |
| 521 | + var test = setup_test('<select>', {}); |
533 | 522 | test.selectize.destroy();
|
534 | 523 | expect(test.selectize.$input[0].selectize).to.be.equal(undefined);
|
535 |
| - test.teardown(); |
536 | 524 | });
|
537 | 525 | it('should unbind events on window', function() {
|
538 |
| - test = setup_test('<select>', {}); |
| 526 | + var test = setup_test('<select>', {}); |
539 | 527 | test.selectize.destroy();
|
540 | 528 | expect(has_namespaced_event($(window), test.selectize.eventNS)).to.be.equal(false);
|
541 |
| - test.teardown(); |
542 | 529 | });
|
543 | 530 | it('should unbind events on document', function() {
|
544 |
| - test = setup_test('<select>', {}); |
| 531 | + var test = setup_test('<select>', {}); |
545 | 532 | test.selectize.destroy();
|
546 | 533 | expect(has_namespaced_event($(document), test.selectize.eventNS)).to.be.equal(false);
|
547 |
| - test.teardown(); |
548 | 534 | });
|
549 | 535 | it('should unbind events on <body>', function() {
|
550 |
| - test = setup_test('<select>', {}); |
| 536 | + var test = setup_test('<select>', {}); |
551 | 537 | test.selectize.destroy();
|
552 | 538 | expect(has_namespaced_event($('body'), test.selectize.eventNS)).to.be.equal(false);
|
553 |
| - test.teardown(); |
554 | 539 | });
|
555 | 540 | });
|
556 | 541 |
|
|
0 commit comments