File: on%28%29.js

package info (click to toggle)
datatables.js 1.10.13%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,232 kB
  • ctags: 1,329
  • sloc: xml: 10,249; php: 4,387; sh: 492; makefile: 21
file content (78 lines) | stat: -rw-r--r-- 1,771 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// todo tests
// - Check it exists and is a function
// - Able to add a single event
// - Able to listen for multiple events with a single call
// - Event handlers are correctly triggered
// - The callback function is passed at least the event object as the first parameter (exact parameters depend upon the event)
// - returns API instance

describe( 'core- on()', function() {
	var table;

	dt.libs( {
		js:  [ 'jquery', 'datatables' ],
		css: [ 'datatables' ]
	} );

	dt.html( 'basic' );

	it( '.dt name space is automatically added when using `on`', function () {
		var drawPass = false;

		table = $('#example').DataTable();

		table.on( 'draw', function () {
			drawPass = true;
		} );
		table.draw();

		expect( drawPass ).toBe( true );
	} );

	it( 'Name space can be passed in manually', function () {
		var drawPass = false;

		table.on( 'draw.dt', function () {
			drawPass = true;
		} );
		table.draw();

		expect( drawPass ).toBe( true );
	} );

	it( 'Multiple events can be subscripted with manual namespaces', function () {
		var drawPass = false;
		var pagePass = false;

		table.on( 'draw.dt page.dt', function (e) {
			if ( e.type === 'draw' ) {
				drawPass = true;
			}
			else if ( e.type === 'page' ) {
				pagePass = true;
			}
		} );
		table.page(2).draw(false);

		expect( drawPass ).toBe( true );
		expect( pagePass ).toBe( true );
	} );

	it( 'Multiple events can be subscripted without manual namespaces', function () {
		var drawPass = false;
		var pagePass = false;

		table.on( 'draw page', function (e) {
			if ( e.type === 'draw' ) {
				drawPass = true;
			}
			else if ( e.type === 'page' ) {
				pagePass = true;
			}
		} );
		table.page(3).draw(false);

		expect( drawPass ).toBe( true );
		expect( pagePass ).toBe( true );
	} );
} );