forked from WickyNilliams/enquire.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryHandler.js
132 lines (96 loc) · 2.74 KB
/
QueryHandler.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*global describe: true, beforeEach: true, it: true, expect: true, jasmine:true, QueryHandler:true */
(function() {
describe('QueryHandler', function() {
'use strict';
var options;
beforeEach(function() {
options = jasmine.createSpyObj('options', ['match', 'unmatch', 'setup', 'destroy']);
});
it('is initialised if setup not deferred', function() {
// Arrange & act
var handler = new QueryHandler(options);
// Assert
expect(handler.initialised).toBe(true);
});
it('is not initialised if setup deferred', function () {
// Arrange
options.deferSetup = true;
// Act
var handler = new QueryHandler(options);
// Assert
expect(handler.initialised).toBeFalsy();
});
it('stores supplied handler', function() {
// Arrange & act
var handler = new QueryHandler(options);
// Assert
expect(handler.options).toBe(options);
});
it('calls setup handler and sets to initialised during setup', function() {
// Arrange
options.deferSetup = true;
var handler = new QueryHandler(options);
// Act
handler.setup();
// Assert
expect(options.setup).toHaveBeenCalled();
expect(handler.initialised).toBe(true);
});
it('will call a setup function followed by on', function() {
// Arrange
var handler;
options.deferSetup = true;
handler = new QueryHandler(options);
// Act
handler.on();
// Assert
expect(options.setup).toHaveBeenCalled();
expect(options.match).toHaveBeenCalled();
});
it('calls match handler when turned on', function() {
// Arrange
var handler = new QueryHandler(options);
// Act
handler.on();
// Assert
expect(options.match).toHaveBeenCalled();
});
it('calls unmatch handler when turned off', function() {
// Arrange
var handler = new QueryHandler(options);
// Act
handler.off();
// Assert
expect(options.unmatch).toHaveBeenCalled();
});
it('can test for equality', function() {
// Arrange
var handler = new QueryHandler(options),
equalityByObject,
equalityByFunction;
// Act
equalityByObject = handler.equals(options);
equalityByFunction = handler.equals(options.match);
// Assert
expect(equalityByObject).toBe(true);
expect(equalityByFunction).toBe(true);
});
it('calls through to destroy if supplied', function() {
// Arrange
var handler = new QueryHandler(options);
// Act
handler.destroy();
// Assert
expect(options.destroy).toHaveBeenCalled();
});
it('calls through to unmatch if destroy not available', function() {
// Arrange
var spy = jasmine.createSpyObj('options', ['match', 'unmatch']),
handler = new QueryHandler(spy);
// Act
handler.destroy();
// Assert
expect(spy.unmatch).toHaveBeenCalled();
});
});
}());