jasmine-core 2.5.0 → 2.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/console/console.js +1 -1
- data/lib/jasmine-core/boot/boot.js +4 -1
- data/lib/jasmine-core/boot.js +5 -2
- data/lib/jasmine-core/jasmine-html.js +95 -31
- data/lib/jasmine-core/jasmine.css +1 -0
- data/lib/jasmine-core/jasmine.js +3635 -1684
- data/lib/jasmine-core/node_boot.js +1 -1
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +10 -0
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +94 -14
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +26 -8
- data/lib/jasmine-core/spec/core/EnvSpec.js +142 -10
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +52 -7
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +132 -4
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +333 -23
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +16 -1
- data/lib/jasmine-core/spec/core/SpecSpec.js +30 -8
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +225 -1
- data/lib/jasmine-core/spec/core/SpySpec.js +44 -2
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +28 -5
- data/lib/jasmine-core/spec/core/SuiteSpec.js +14 -19
- data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +71 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +32 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +32 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +13 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +13 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +48 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +339 -38
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +156 -3
- data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
- data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +231 -8
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +42 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +780 -4
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +37 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +4 -0
- data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
- data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
- data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
- data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
- data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +105 -23
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +34 -0
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +1 -1
- data/lib/jasmine-core/version.rb +1 -1
- metadata +19 -4
@@ -1,20 +1,39 @@
|
|
1
1
|
describe("toEqual", function() {
|
2
|
+
"use strict";
|
3
|
+
|
4
|
+
function compareEquals(actual, expected) {
|
5
|
+
var util = jasmineUnderTest.matchersUtil,
|
6
|
+
matcher = jasmineUnderTest.matchers.toEqual(util);
|
7
|
+
|
8
|
+
var result = matcher.compare(actual, expected);
|
9
|
+
|
10
|
+
return result;
|
11
|
+
}
|
12
|
+
|
2
13
|
it("delegates to equals function", function() {
|
3
14
|
var util = {
|
4
|
-
equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
|
15
|
+
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
16
|
+
buildFailureMessage: function() {
|
17
|
+
return 'does not matter'
|
18
|
+
},
|
19
|
+
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
|
5
20
|
},
|
6
21
|
matcher = jasmineUnderTest.matchers.toEqual(util),
|
7
22
|
result;
|
8
23
|
|
9
24
|
result = matcher.compare(1, 1);
|
10
25
|
|
11
|
-
expect(util.equals).toHaveBeenCalledWith(1, 1, []);
|
26
|
+
expect(util.equals).toHaveBeenCalledWith(1, 1, [], jasmine.anything());
|
12
27
|
expect(result.pass).toBe(true);
|
13
28
|
});
|
14
29
|
|
15
30
|
it("delegates custom equality testers, if present", function() {
|
16
31
|
var util = {
|
17
|
-
equals: jasmine.createSpy('delegated-equals').and.returnValue(true)
|
32
|
+
equals: jasmine.createSpy('delegated-equals').and.returnValue(true),
|
33
|
+
buildFailureMessage: function() {
|
34
|
+
return 'does not matter'
|
35
|
+
},
|
36
|
+
DiffBuilder: jasmineUnderTest.matchersUtil.DiffBuilder
|
18
37
|
},
|
19
38
|
customEqualityTesters = ['a', 'b'],
|
20
39
|
matcher = jasmineUnderTest.matchers.toEqual(util, customEqualityTesters),
|
@@ -22,7 +41,764 @@ describe("toEqual", function() {
|
|
22
41
|
|
23
42
|
result = matcher.compare(1, 1);
|
24
43
|
|
25
|
-
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b']);
|
44
|
+
expect(util.equals).toHaveBeenCalledWith(1, 1, ['a', 'b'], jasmine.anything());
|
26
45
|
expect(result.pass).toBe(true);
|
27
46
|
});
|
47
|
+
|
48
|
+
it("reports the difference between objects that are not equal", function() {
|
49
|
+
var actual = {x: 1, y: 3},
|
50
|
+
expected = {x: 2, y: 3},
|
51
|
+
message = "Expected $.x = 1 to equal 2.";
|
52
|
+
|
53
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
54
|
+
});
|
55
|
+
|
56
|
+
it("reports the difference between nested objects that are not equal", function() {
|
57
|
+
var actual = {x: {y: 1}},
|
58
|
+
expected = {x: {y: 2}},
|
59
|
+
message = "Expected $.x.y = 1 to equal 2.";
|
60
|
+
|
61
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
62
|
+
});
|
63
|
+
|
64
|
+
it("formats property access so that it's valid JavaScript", function() {
|
65
|
+
var actual = {'my prop': 1},
|
66
|
+
expected = {'my prop': 2},
|
67
|
+
message = "Expected $['my prop'] = 1 to equal 2.";
|
68
|
+
|
69
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
70
|
+
});
|
71
|
+
|
72
|
+
it("reports missing properties", function() {
|
73
|
+
var actual = {x: {}},
|
74
|
+
expected = {x: {y: 1}},
|
75
|
+
message =
|
76
|
+
"Expected $.x to have properties\n" +
|
77
|
+
" y: 1";
|
78
|
+
|
79
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
80
|
+
});
|
81
|
+
|
82
|
+
it("reports extra properties", function() {
|
83
|
+
var actual = {x: {y: 1, z: 2}},
|
84
|
+
expected = {x: {}},
|
85
|
+
message =
|
86
|
+
"Expected $.x not to have properties\n" +
|
87
|
+
" y: 1\n" +
|
88
|
+
" z: 2";
|
89
|
+
|
90
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
91
|
+
});
|
92
|
+
|
93
|
+
it("pretty-prints properties", function() {
|
94
|
+
var actual = {x: {y: 'foo bar'}},
|
95
|
+
expected = {x: {}},
|
96
|
+
message =
|
97
|
+
"Expected $.x not to have properties\n" +
|
98
|
+
" y: 'foo bar'"
|
99
|
+
|
100
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
101
|
+
});
|
102
|
+
|
103
|
+
it("reports extra and missing properties together", function() {
|
104
|
+
var actual = {x: {y: 1, z: 2, f: 4}},
|
105
|
+
expected = {x: {y: 1, z: 2, g: 3}},
|
106
|
+
message =
|
107
|
+
"Expected $.x to have properties\n" +
|
108
|
+
" g: 3\n" +
|
109
|
+
"Expected $.x not to have properties\n" +
|
110
|
+
" f: 4";
|
111
|
+
|
112
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
113
|
+
});
|
114
|
+
|
115
|
+
it("reports extra and missing properties of the root-level object", function() {
|
116
|
+
var actual = {x: 1},
|
117
|
+
expected = {a: 1},
|
118
|
+
message =
|
119
|
+
"Expected object to have properties\n" +
|
120
|
+
" a: 1\n" +
|
121
|
+
"Expected object not to have properties\n" +
|
122
|
+
" x: 1";
|
123
|
+
|
124
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
125
|
+
});
|
126
|
+
|
127
|
+
it("reports multiple incorrect values", function() {
|
128
|
+
var actual = {x: 1, y: 2},
|
129
|
+
expected = {x: 3, y: 4},
|
130
|
+
message =
|
131
|
+
"Expected $.x = 1 to equal 3.\n" +
|
132
|
+
"Expected $.y = 2 to equal 4.";
|
133
|
+
|
134
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
135
|
+
});
|
136
|
+
|
137
|
+
it("reports mismatch between actual child object and expected child number", function() {
|
138
|
+
var actual = {x: {y: 2}},
|
139
|
+
expected = {x: 1},
|
140
|
+
message = "Expected $.x = Object({ y: 2 }) to equal 1.";
|
141
|
+
|
142
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
143
|
+
});
|
144
|
+
|
145
|
+
it("uses the default failure message if actual is not an object", function() {
|
146
|
+
var actual = 1,
|
147
|
+
expected = {x: {}},
|
148
|
+
message = "Expected 1 to equal Object({ x: Object({ }) }).";
|
149
|
+
|
150
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
151
|
+
});
|
152
|
+
|
153
|
+
it("uses the default failure message if expected is not an object", function() {
|
154
|
+
var actual = {x: {}},
|
155
|
+
expected = 1,
|
156
|
+
message = "Expected Object({ x: Object({ }) }) to equal 1.";
|
157
|
+
|
158
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
159
|
+
});
|
160
|
+
|
161
|
+
it("uses the default failure message given arrays with different lengths", function() {
|
162
|
+
var actual = [1, 2],
|
163
|
+
expected = [1, 2, 3],
|
164
|
+
message = 'Expected $.length = 2 to equal 3.\n' +
|
165
|
+
'Expected $[2] = undefined to equal 3.';
|
166
|
+
|
167
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
168
|
+
});
|
169
|
+
|
170
|
+
it("reports a mismatch between elements of equal-length arrays", function() {
|
171
|
+
var actual = [1, 2, 5],
|
172
|
+
expected = [1, 2, 3],
|
173
|
+
message = "Expected $[2] = 5 to equal 3.";
|
174
|
+
|
175
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
176
|
+
});
|
177
|
+
|
178
|
+
it("reports a mismatch between multiple array elements", function() {
|
179
|
+
var actual = [2, 2, 5],
|
180
|
+
expected = [1, 2, 3],
|
181
|
+
message =
|
182
|
+
"Expected $[0] = 2 to equal 1.\n" +
|
183
|
+
"Expected $[2] = 5 to equal 3.";
|
184
|
+
|
185
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
186
|
+
});
|
187
|
+
|
188
|
+
it("reports a mismatch between properties of objects in arrays", function() {
|
189
|
+
var actual = [{x: 1}],
|
190
|
+
expected = [{x: 2}],
|
191
|
+
message = "Expected $[0].x = 1 to equal 2.";
|
192
|
+
|
193
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
194
|
+
});
|
195
|
+
|
196
|
+
it("reports a mismatch between arrays in objects", function() {
|
197
|
+
var actual = {x: [1]},
|
198
|
+
expected = {x: [2]},
|
199
|
+
message =
|
200
|
+
"Expected $.x[0] = 1 to equal 2.";
|
201
|
+
|
202
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
203
|
+
});
|
204
|
+
|
205
|
+
it("reports mismatches between nested arrays", function() {
|
206
|
+
var actual = [[1]],
|
207
|
+
expected = [[2]],
|
208
|
+
message =
|
209
|
+
"Expected $[0][0] = 1 to equal 2.";
|
210
|
+
|
211
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
212
|
+
});
|
213
|
+
|
214
|
+
it("reports mismatches between arrays of different types", function() {
|
215
|
+
jasmine.getEnv().requireFunctioningTypedArrays();
|
216
|
+
|
217
|
+
var actual = new Uint32Array([1, 2, 3]),
|
218
|
+
expected = new Uint16Array([1, 2, 3]),
|
219
|
+
message = "Expected Uint32Array [ 1, 2, 3 ] to equal Uint16Array [ 1, 2, 3 ].";
|
220
|
+
|
221
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
222
|
+
});
|
223
|
+
|
224
|
+
it("reports mismatches involving NaN", function() {
|
225
|
+
var actual = {x: 0},
|
226
|
+
expected = {x: 0/0},
|
227
|
+
message = "Expected $.x = 0 to equal NaN.";
|
228
|
+
|
229
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
230
|
+
});
|
231
|
+
|
232
|
+
it("reports mismatches involving regular expressions", function() {
|
233
|
+
var actual = {x: '1'},
|
234
|
+
expected = {x: /1/},
|
235
|
+
message = "Expected $.x = '1' to equal /1/.";
|
236
|
+
|
237
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
238
|
+
});
|
239
|
+
|
240
|
+
it("reports mismatches involving infinities", function() {
|
241
|
+
var actual = {x: 0},
|
242
|
+
expected = {x: 1/0},
|
243
|
+
message = "Expected $.x = 0 to equal Infinity.";
|
244
|
+
|
245
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
246
|
+
});
|
247
|
+
|
248
|
+
it("reports mismatches involving booleans", function() {
|
249
|
+
var actual = {x: false},
|
250
|
+
expected = {x: true},
|
251
|
+
message = "Expected $.x = false to equal true.";
|
252
|
+
|
253
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
254
|
+
});
|
255
|
+
|
256
|
+
it("reports mismatches involving strings", function() {
|
257
|
+
var actual = {x: 'foo'},
|
258
|
+
expected = {x: 'bar'},
|
259
|
+
message = "Expected $.x = 'foo' to equal 'bar'.";
|
260
|
+
|
261
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
262
|
+
});
|
263
|
+
|
264
|
+
it("reports mismatches involving undefined", function() {
|
265
|
+
var actual = {x: void 0},
|
266
|
+
expected = {x: 0},
|
267
|
+
message = "Expected $.x = undefined to equal 0.";
|
268
|
+
|
269
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
270
|
+
});
|
271
|
+
|
272
|
+
it("reports mismatches involving null", function() {
|
273
|
+
var actual = {x: null},
|
274
|
+
expected = {x: 0},
|
275
|
+
message = "Expected $.x = null to equal 0.";
|
276
|
+
|
277
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
278
|
+
});
|
279
|
+
|
280
|
+
it("reports mismatches between objects with different constructors", function () {
|
281
|
+
function Foo() {}
|
282
|
+
function Bar() {}
|
283
|
+
|
284
|
+
var actual = {x: new Foo()},
|
285
|
+
expected = {x: new Bar()},
|
286
|
+
message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
|
287
|
+
|
288
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
289
|
+
});
|
290
|
+
|
291
|
+
it("reports type mismatches at the root level", function () {
|
292
|
+
function Foo() {}
|
293
|
+
function Bar() {}
|
294
|
+
|
295
|
+
var actual = new Foo(),
|
296
|
+
expected = new Bar(),
|
297
|
+
message = "Expected object to be a kind of Bar, but was Foo({ }).";
|
298
|
+
|
299
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
300
|
+
});
|
301
|
+
|
302
|
+
function constructorIsNotEnumerable() {
|
303
|
+
// in IE8, the constructor property is not enumerable, even if it is an
|
304
|
+
// own property of the object.
|
305
|
+
// Objects that differ only by an own `constructor` property are thus
|
306
|
+
// considered equal in IE8.
|
307
|
+
for (var key in {constructor: 1}) {
|
308
|
+
return false;
|
309
|
+
}
|
310
|
+
return true;
|
311
|
+
}
|
312
|
+
|
313
|
+
it("reports mismatches between objects with their own constructor property", function () {
|
314
|
+
if (constructorIsNotEnumerable()) {
|
315
|
+
return;
|
316
|
+
}
|
317
|
+
|
318
|
+
function Foo() {}
|
319
|
+
function Bar() {}
|
320
|
+
|
321
|
+
var actual = {x: {constructor: 'blerf'}},
|
322
|
+
expected = {x: {constructor: 'ftarrh'}},
|
323
|
+
message = "Expected $.x.constructor = 'blerf' to equal 'ftarrh'.";
|
324
|
+
|
325
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
326
|
+
});
|
327
|
+
|
328
|
+
it("reports mismatches between an object with a real constructor and one with its own constructor property", function () {
|
329
|
+
if (constructorIsNotEnumerable()) {
|
330
|
+
return;
|
331
|
+
}
|
332
|
+
|
333
|
+
function Foo() {}
|
334
|
+
function Bar() {}
|
335
|
+
|
336
|
+
var actual = {x: {}},
|
337
|
+
expected = {x: {constructor: 'ftarrh'}},
|
338
|
+
message =
|
339
|
+
"Expected $.x to have properties\n" +
|
340
|
+
" constructor: 'ftarrh'";
|
341
|
+
|
342
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
343
|
+
expect(compareEquals(expected, actual).message).toEqual(
|
344
|
+
"Expected $.x not to have properties\n constructor: 'ftarrh'"
|
345
|
+
);
|
346
|
+
});
|
347
|
+
|
348
|
+
it("reports mismatches between 0 and -0", function() {
|
349
|
+
var actual = {x: 0},
|
350
|
+
expected = {x: -0},
|
351
|
+
message = "Expected $.x = 0 to equal -0.";
|
352
|
+
|
353
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
354
|
+
});
|
355
|
+
|
356
|
+
it("reports mismatches between Errors", function() {
|
357
|
+
var actual = {x: new Error("the error you got")},
|
358
|
+
expected = {x: new Error("the error you want")},
|
359
|
+
message = "Expected $.x = Error: the error you got to equal Error: the error you want.";
|
360
|
+
|
361
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
362
|
+
});
|
363
|
+
|
364
|
+
it("reports mismatches between Functions", function() {
|
365
|
+
var actual = {x: function() {}},
|
366
|
+
expected = {x: function() {}},
|
367
|
+
message = "Expected $.x = Function to equal Function.";
|
368
|
+
|
369
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
370
|
+
});
|
371
|
+
|
372
|
+
// == Sets ==
|
373
|
+
|
374
|
+
it("reports mismatches between Sets", function() {
|
375
|
+
jasmine.getEnv().requireFunctioningSets();
|
376
|
+
|
377
|
+
var actual = new Set();
|
378
|
+
actual.add(1);
|
379
|
+
var expected = new Set();
|
380
|
+
expected.add(2);
|
381
|
+
var message = 'Expected Set( 1 ) to equal Set( 2 ).';
|
382
|
+
|
383
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
384
|
+
});
|
385
|
+
|
386
|
+
it("reports deep mismatches within Sets", function() {
|
387
|
+
jasmine.getEnv().requireFunctioningSets();
|
388
|
+
|
389
|
+
var actual = new Set();
|
390
|
+
actual.add({x: 1});
|
391
|
+
var expected = new Set();
|
392
|
+
expected.add({x: 2});
|
393
|
+
var message = 'Expected Set( Object({ x: 1 }) ) to equal Set( Object({ x: 2 }) ).';
|
394
|
+
|
395
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
396
|
+
});
|
397
|
+
|
398
|
+
it("reports mismatches between Sets nested in objects", function() {
|
399
|
+
jasmine.getEnv().requireFunctioningSets();
|
400
|
+
|
401
|
+
var actualSet = new Set();
|
402
|
+
actualSet.add(1);
|
403
|
+
var expectedSet = new Set();
|
404
|
+
expectedSet.add(2);
|
405
|
+
|
406
|
+
var actual = { sets: [actualSet] };
|
407
|
+
var expected = { sets: [expectedSet] };
|
408
|
+
var message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
|
409
|
+
|
410
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
411
|
+
});
|
412
|
+
|
413
|
+
it("reports mismatches between Sets of different lengths", function() {
|
414
|
+
jasmine.getEnv().requireFunctioningSets();
|
415
|
+
|
416
|
+
var actual = new Set();
|
417
|
+
actual.add(1);
|
418
|
+
actual.add(2);
|
419
|
+
var expected = new Set();
|
420
|
+
expected.add(2);
|
421
|
+
var message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
|
422
|
+
|
423
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
424
|
+
});
|
425
|
+
|
426
|
+
it("reports mismatches between Sets where actual is missing a value from expected", function() {
|
427
|
+
jasmine.getEnv().requireFunctioningSets();
|
428
|
+
|
429
|
+
// Use 'duplicate' object in actual so sizes match
|
430
|
+
var actual = new Set();
|
431
|
+
actual.add({x: 1});
|
432
|
+
actual.add({x: 1});
|
433
|
+
var expected = new Set();
|
434
|
+
expected.add({x: 1});
|
435
|
+
expected.add({x: 2});
|
436
|
+
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 1 }) ) to equal Set( Object({ x: 1 }), Object({ x: 2 }) ).';
|
437
|
+
|
438
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
439
|
+
});
|
440
|
+
|
441
|
+
it("reports mismatches between Sets where actual has a value missing from expected", function() {
|
442
|
+
jasmine.getEnv().requireFunctioningSets();
|
443
|
+
|
444
|
+
// Use 'duplicate' object in expected so sizes match
|
445
|
+
var actual = new Set();
|
446
|
+
actual.add({x: 1});
|
447
|
+
actual.add({x: 2});
|
448
|
+
var expected = new Set();
|
449
|
+
expected.add({x: 1});
|
450
|
+
expected.add({x: 1});
|
451
|
+
var message = 'Expected Set( Object({ x: 1 }), Object({ x: 2 }) ) to equal Set( Object({ x: 1 }), Object({ x: 1 }) ).';
|
452
|
+
|
453
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
454
|
+
});
|
455
|
+
|
456
|
+
// == Maps ==
|
457
|
+
|
458
|
+
it("does not report mismatches between deep equal Maps", function() {
|
459
|
+
jasmine.getEnv().requireFunctioningMaps();
|
460
|
+
|
461
|
+
// values are the same but with different object identity
|
462
|
+
var actual = new Map();
|
463
|
+
actual.set('a',{x:1});
|
464
|
+
var expected = new Map();
|
465
|
+
expected.set('a',{x:1});
|
466
|
+
|
467
|
+
expect(compareEquals(actual, expected).pass).toBe(true);
|
468
|
+
});
|
469
|
+
|
470
|
+
it("reports deep mismatches within Maps", function() {
|
471
|
+
jasmine.getEnv().requireFunctioningMaps();
|
472
|
+
|
473
|
+
var actual = new Map();
|
474
|
+
actual.set('a',{x:1});
|
475
|
+
var expected = new Map();
|
476
|
+
expected.set('a',{x:2});
|
477
|
+
var message = "Expected Map( [ 'a', Object({ x: 1 }) ] ) to equal Map( [ 'a', Object({ x: 2 }) ] ).";
|
478
|
+
|
479
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
480
|
+
});
|
481
|
+
|
482
|
+
it("reports mismatches between Maps nested in objects", function() {
|
483
|
+
jasmine.getEnv().requireFunctioningMaps();
|
484
|
+
|
485
|
+
var actual = {Maps:[new Map()]};
|
486
|
+
actual.Maps[0].set('a',1);
|
487
|
+
var expected = {Maps:[new Map()]};
|
488
|
+
expected.Maps[0].set('a',2);
|
489
|
+
|
490
|
+
var message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
|
491
|
+
|
492
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
493
|
+
});
|
494
|
+
|
495
|
+
it("reports mismatches between Maps of different lengths", function() {
|
496
|
+
jasmine.getEnv().requireFunctioningMaps();
|
497
|
+
|
498
|
+
var actual = new Map();
|
499
|
+
actual.set('a',1);
|
500
|
+
var expected = new Map();
|
501
|
+
expected.set('a',2);
|
502
|
+
expected.set('b',1);
|
503
|
+
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
|
504
|
+
|
505
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
506
|
+
});
|
507
|
+
|
508
|
+
it("reports mismatches between Maps with equal values but differing keys", function() {
|
509
|
+
jasmine.getEnv().requireFunctioningMaps();
|
510
|
+
|
511
|
+
var actual = new Map();
|
512
|
+
actual.set('a',1);
|
513
|
+
var expected = new Map();
|
514
|
+
expected.set('b',1);
|
515
|
+
var message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'b', 1 ] ).";
|
516
|
+
|
517
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
518
|
+
});
|
519
|
+
|
520
|
+
it("does not report mismatches between Maps with keys with same object identity", function() {
|
521
|
+
jasmine.getEnv().requireFunctioningMaps();
|
522
|
+
var key = {x: 1};
|
523
|
+
var actual = new Map();
|
524
|
+
actual.set(key,2);
|
525
|
+
var expected = new Map();
|
526
|
+
expected.set(key,2);
|
527
|
+
|
528
|
+
expect(compareEquals(actual, expected).pass).toBe(true);
|
529
|
+
});
|
530
|
+
|
531
|
+
it("reports mismatches between Maps with identical keys with different object identity", function() {
|
532
|
+
jasmine.getEnv().requireFunctioningMaps();
|
533
|
+
|
534
|
+
var actual = new Map();
|
535
|
+
actual.set({x:1},2);
|
536
|
+
var expected = new Map();
|
537
|
+
expected.set({x:1},2);
|
538
|
+
var message = "Expected Map( [ Object({ x: 1 }), 2 ] ) to equal Map( [ Object({ x: 1 }), 2 ] ).";
|
539
|
+
|
540
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
541
|
+
});
|
542
|
+
|
543
|
+
it("does not report mismatches when comparing Map key to jasmine.anything()", function() {
|
544
|
+
jasmine.getEnv().requireFunctioningMaps();
|
545
|
+
|
546
|
+
var actual = new Map();
|
547
|
+
actual.set('a',1);
|
548
|
+
var expected = new Map();
|
549
|
+
expected.set(jasmineUnderTest.anything(),1);
|
550
|
+
|
551
|
+
expect(compareEquals(actual, expected).pass).toBe(true);
|
552
|
+
});
|
553
|
+
|
554
|
+
it("does not report mismatches when comparing Maps with the same symbol keys", function() {
|
555
|
+
jasmine.getEnv().requireFunctioningMaps();
|
556
|
+
jasmine.getEnv().requireFunctioningSymbols();
|
557
|
+
|
558
|
+
var key = Symbol();
|
559
|
+
var actual = new Map();
|
560
|
+
actual.set(key,1);
|
561
|
+
var expected = new Map();
|
562
|
+
expected.set(key,1);
|
563
|
+
|
564
|
+
expect(compareEquals(actual, expected).pass).toBe(true);
|
565
|
+
});
|
566
|
+
|
567
|
+
it("reports mismatches between Maps with different symbol keys", function() {
|
568
|
+
jasmine.getEnv().requireFunctioningMaps();
|
569
|
+
jasmine.getEnv().requireFunctioningSymbols();
|
570
|
+
|
571
|
+
var actual = new Map();
|
572
|
+
actual.set(Symbol(),1);
|
573
|
+
var expected = new Map();
|
574
|
+
expected.set(Symbol(),1);
|
575
|
+
var message = "Expected Map( [ Symbol(), 1 ] ) to equal Map( [ Symbol(), 1 ] ).";
|
576
|
+
|
577
|
+
expect(compareEquals(actual, expected).message).toBe(message);
|
578
|
+
});
|
579
|
+
|
580
|
+
it("does not report mismatches when comparing Map symbol key to jasmine.anything()", function() {
|
581
|
+
jasmine.getEnv().requireFunctioningMaps();
|
582
|
+
jasmine.getEnv().requireFunctioningSymbols();
|
583
|
+
|
584
|
+
var actual = new Map();
|
585
|
+
actual.set(Symbol(),1);
|
586
|
+
var expected = new Map();
|
587
|
+
expected.set(jasmineUnderTest.anything(),1);
|
588
|
+
|
589
|
+
expect(compareEquals(actual, expected).pass).toBe(true);
|
590
|
+
});
|
591
|
+
|
592
|
+
function isNotRunningInBrowser() {
|
593
|
+
return typeof document === 'undefined'
|
594
|
+
}
|
595
|
+
|
596
|
+
it("reports mismatches between DOM nodes with different tags", function() {
|
597
|
+
if(isNotRunningInBrowser()) {
|
598
|
+
return;
|
599
|
+
}
|
600
|
+
|
601
|
+
var actual = {a: document.createElement('div')},
|
602
|
+
expected = {a: document.createElement('p')},
|
603
|
+
message = 'Expected $.a = HTMLNode to equal HTMLNode.';
|
604
|
+
|
605
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
606
|
+
});
|
607
|
+
|
608
|
+
it('reports mismatches between DOM nodes with different content', function() {
|
609
|
+
if(isNotRunningInBrowser()) {
|
610
|
+
return;
|
611
|
+
}
|
612
|
+
|
613
|
+
var nodeA = document.createElement('div'),
|
614
|
+
nodeB = document.createElement('div');
|
615
|
+
|
616
|
+
nodeA.innerText = 'foo'
|
617
|
+
nodeB.innerText = 'bar'
|
618
|
+
|
619
|
+
var actual = {a: nodeA},
|
620
|
+
expected = {a: nodeB},
|
621
|
+
message = 'Expected $.a = HTMLNode to equal HTMLNode.';
|
622
|
+
|
623
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
624
|
+
})
|
625
|
+
|
626
|
+
it("reports mismatches between a DOM node and a bare Object", function() {
|
627
|
+
if(isNotRunningInBrowser()) {
|
628
|
+
return;
|
629
|
+
}
|
630
|
+
|
631
|
+
var actual = {a: document.createElement('div')},
|
632
|
+
expected = {a: {}},
|
633
|
+
message = 'Expected $.a = HTMLNode to equal Object({ }).';
|
634
|
+
|
635
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
636
|
+
});
|
637
|
+
|
638
|
+
it("reports asymmetric mismatches", function() {
|
639
|
+
var actual = {a: 1},
|
640
|
+
expected = {a: jasmineUnderTest.any(String)},
|
641
|
+
message = 'Expected $.a = 1 to equal <jasmine.any(String)>.';
|
642
|
+
|
643
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
644
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
645
|
+
});
|
646
|
+
|
647
|
+
it("reports asymmetric mismatches when the asymmetric comparand is the actual value", function() {
|
648
|
+
var actual = {a: jasmineUnderTest.any(String)},
|
649
|
+
expected = {a: 1},
|
650
|
+
message = 'Expected $.a = <jasmine.any(String)> to equal 1.';
|
651
|
+
|
652
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
653
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
654
|
+
});
|
655
|
+
|
656
|
+
it("does not report a mismatch when asymmetric matchers are satisfied", function() {
|
657
|
+
var actual = {a: 'a'},
|
658
|
+
expected = {a: jasmineUnderTest.any(String)};
|
659
|
+
|
660
|
+
expect(compareEquals(actual, expected).message).toEqual('');
|
661
|
+
expect(compareEquals(actual, expected).pass).toBe(true)
|
662
|
+
});
|
663
|
+
|
664
|
+
it("works on big complex stuff", function() {
|
665
|
+
var actual = {
|
666
|
+
foo: [
|
667
|
+
{bar: 1, things: ['a', 'b']},
|
668
|
+
{bar: 2, things: ['a', 'b']}
|
669
|
+
],
|
670
|
+
baz: [
|
671
|
+
{a: {b: 1}}
|
672
|
+
],
|
673
|
+
quux: 1,
|
674
|
+
nan: 0,
|
675
|
+
aRegexp: 'hi',
|
676
|
+
inf: -1/0,
|
677
|
+
boolean: false,
|
678
|
+
notDefined: 0,
|
679
|
+
aNull: void 0
|
680
|
+
}
|
681
|
+
|
682
|
+
var expected = {
|
683
|
+
foo: [
|
684
|
+
{bar: 2, things: ['a', 'b', 'c']},
|
685
|
+
{bar: 2, things: ['a', 'd']}
|
686
|
+
],
|
687
|
+
baz: [
|
688
|
+
{a: {b: 1, c: 1}}
|
689
|
+
],
|
690
|
+
quux: [],
|
691
|
+
nan: 0/0,
|
692
|
+
aRegexp: /hi/,
|
693
|
+
inf: 1/0,
|
694
|
+
boolean: true,
|
695
|
+
notDefined: void 0,
|
696
|
+
aNull: null
|
697
|
+
}
|
698
|
+
|
699
|
+
var message =
|
700
|
+
'Expected $.foo[0].bar = 1 to equal 2.\n' +
|
701
|
+
'Expected $.foo[0].things.length = 2 to equal 3.\n' +
|
702
|
+
"Expected $.foo[0].things[2] = undefined to equal 'c'.\n" +
|
703
|
+
"Expected $.foo[1].things[1] = 'b' to equal 'd'.\n" +
|
704
|
+
'Expected $.baz[0].a to have properties\n' +
|
705
|
+
' c: 1\n' +
|
706
|
+
'Expected $.quux = 1 to equal [ ].\n' +
|
707
|
+
'Expected $.nan = 0 to equal NaN.\n' +
|
708
|
+
"Expected $.aRegexp = 'hi' to equal /hi/.\n" +
|
709
|
+
'Expected $.inf = -Infinity to equal Infinity.\n' +
|
710
|
+
'Expected $.boolean = false to equal true.\n' +
|
711
|
+
'Expected $.notDefined = 0 to equal undefined.\n' +
|
712
|
+
'Expected $.aNull = undefined to equal null.'
|
713
|
+
|
714
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
715
|
+
})
|
716
|
+
|
717
|
+
describe("different length arrays", function() {
|
718
|
+
it("actual array is longer", function() {
|
719
|
+
var actual = [1, 1, 2, 3, 5],
|
720
|
+
expected = [1, 1, 2, 3],
|
721
|
+
message = 'Expected $.length = 5 to equal 4.\n' +
|
722
|
+
'Expected $[4] = 5 to equal undefined.';
|
723
|
+
|
724
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
725
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
726
|
+
});
|
727
|
+
|
728
|
+
it("expected array is longer", function() {
|
729
|
+
var actual = [1, 1, 2, 3],
|
730
|
+
expected = [1, 1, 2, 3, 5],
|
731
|
+
message = 'Expected $.length = 4 to equal 5.\n' +
|
732
|
+
'Expected $[4] = undefined to equal 5.';
|
733
|
+
|
734
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
735
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
736
|
+
});
|
737
|
+
|
738
|
+
it("expected array is longer by 4 elements", function() {
|
739
|
+
var actual = [1, 1, 2],
|
740
|
+
expected = [1, 1, 2, 3, 5, 8, 13],
|
741
|
+
message = 'Expected $.length = 3 to equal 7.\n' +
|
742
|
+
'Expected $[3] = undefined to equal 3.\n' +
|
743
|
+
'Expected $[4] = undefined to equal 5.\n' +
|
744
|
+
'Expected $[5] = undefined to equal 8.\n' +
|
745
|
+
'Expected $[6] = undefined to equal 13.';
|
746
|
+
|
747
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
748
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
749
|
+
});
|
750
|
+
|
751
|
+
it("different length and different elements", function() {
|
752
|
+
var actual = [1],
|
753
|
+
expected = [2, 3],
|
754
|
+
message = 'Expected $.length = 1 to equal 2.\n' +
|
755
|
+
'Expected $[0] = 1 to equal 2.\n' +
|
756
|
+
'Expected $[1] = undefined to equal 3.';
|
757
|
+
|
758
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
759
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
760
|
+
});
|
761
|
+
|
762
|
+
it("object with nested array", function() {
|
763
|
+
var actual = { values: [1, 1, 2, 3] },
|
764
|
+
expected = { values: [1, 1, 2] },
|
765
|
+
message = 'Expected $.values.length = 4 to equal 3.\n' +
|
766
|
+
'Expected $.values[3] = 3 to equal undefined.';
|
767
|
+
|
768
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
769
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
770
|
+
});
|
771
|
+
|
772
|
+
it("array with nested object", function() {
|
773
|
+
var actual = [1, 1, 2, { value: 3 }],
|
774
|
+
expected = [1, 1, 2],
|
775
|
+
message = 'Expected $.length = 4 to equal 3.\n' +
|
776
|
+
'Expected $[3] = Object({ value: 3 }) to equal undefined.';
|
777
|
+
|
778
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
779
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
780
|
+
});
|
781
|
+
|
782
|
+
it("array with nested different length array", function() {
|
783
|
+
var actual = [[1], [1, 2]],
|
784
|
+
expected = [[1, 1], [2]],
|
785
|
+
message = 'Expected $[0].length = 1 to equal 2.\n' +
|
786
|
+
'Expected $[0][1] = undefined to equal 1.\n' +
|
787
|
+
'Expected $[1].length = 2 to equal 1.\n' +
|
788
|
+
'Expected $[1][0] = 1 to equal 2.\n' +
|
789
|
+
'Expected $[1][1] = 2 to equal undefined.';
|
790
|
+
|
791
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
792
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
793
|
+
});
|
794
|
+
|
795
|
+
it("last element of longer array is undefined", function() {
|
796
|
+
var actual = [1, 2],
|
797
|
+
expected = [1, 2, void 0],
|
798
|
+
message = 'Expected $.length = 2 to equal 3.';
|
799
|
+
|
800
|
+
expect(compareEquals(actual, expected).pass).toBe(false)
|
801
|
+
expect(compareEquals(actual, expected).message).toEqual(message);
|
802
|
+
});
|
803
|
+
})
|
28
804
|
});
|