1 |
|
2 | var tf = new TableFilter('demo', {
|
3 | base_path: '../dist/tablefilter/'
|
4 | });
|
5 | tf.init();
|
6 |
|
7 | module('Sanity checks');
|
8 | test('Emitter instance', function() {
|
9 | deepEqual(typeof tf.emitter, 'object', 'Emitter instanciated');
|
10 | deepEqual(typeof tf.emitter.events, 'object', 'Emitter events property');
|
11 | deepEqual(typeof tf.emitter.on, 'function', 'Emitter on method');
|
12 | deepEqual(typeof tf.emitter.off, 'function', 'Emitter off method');
|
13 | deepEqual(typeof tf.emitter.emit, 'function', 'Emitter emit method');
|
14 | });
|
15 |
|
16 | module('Behaviour');
|
17 | test('Can subscribe', function(){
|
18 | var emitter = tf.emitter;
|
19 | var output = null;
|
20 | emitter.on(['before-filtering'],
|
21 | function(){ output = 'before-filtering'; });
|
22 |
|
23 | tf.filter();
|
24 |
|
25 | deepEqual(emitter.events['before-filtering'].length, 1,
|
26 | 'Expected number of listeners');
|
27 | deepEqual(output, 'before-filtering', 'Expected output');
|
28 | });
|
29 |
|
30 | test('Can unsubscribe', function(){
|
31 | var emitter = tf.emitter;
|
32 | var output = null;
|
33 | emitter.off(['before-filtering'],
|
34 | function(){ output = 'before-filtering'; });
|
35 |
|
36 | tf.filter();
|
37 |
|
38 | deepEqual(emitter.events['before-filtering'].length, 0,
|
39 | 'Expected number of listeners');
|
40 | deepEqual(output, null, 'Expected output');
|
41 | });
|
42 |
|
43 | test('Can emit', function(){
|
44 | var emitter = tf.emitter;
|
45 | var output = null;
|
46 | emitter.on(['hello'], function(arg){ output = arg; });
|
47 |
|
48 | emitter.emit('hello', 'world');
|
49 |
|
50 | deepEqual(output, 'world', 'Event emitted');
|
51 | });
|
52 |
|
53 | module('Tear-down');
|
54 | test('can destroy TableFilter DOM elements', function() {
|
55 | tf.destroy();
|
56 | deepEqual(tf.isInitialized(), false, 'Filters removed');
|
57 | });
|