jasmine-core 2.5.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/console/console.js +1 -1
  3. data/lib/jasmine-core/boot/boot.js +4 -1
  4. data/lib/jasmine-core/boot.js +5 -2
  5. data/lib/jasmine-core/jasmine-html.js +19 -1
  6. data/lib/jasmine-core/jasmine.js +2859 -1571
  7. data/lib/jasmine-core/node_boot.js +1 -1
  8. data/lib/jasmine-core/spec/core/ClearStackSpec.js +67 -0
  9. data/lib/jasmine-core/spec/core/EnvSpec.js +100 -10
  10. data/lib/jasmine-core/spec/core/ExpectationSpec.js +52 -7
  11. data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +94 -0
  12. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +37 -1
  13. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +37 -0
  14. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +183 -0
  15. data/lib/jasmine-core/spec/core/SpySpec.js +44 -2
  16. data/lib/jasmine-core/spec/core/SuiteSpec.js +3 -18
  17. data/lib/jasmine-core/spec/core/UtilSpec.js +71 -0
  18. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +13 -0
  19. data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +13 -0
  20. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +47 -0
  21. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +85 -14
  22. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +45 -3
  23. data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
  24. data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
  25. data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
  26. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +57 -1
  27. data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
  28. data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
  29. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +492 -4
  30. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
  31. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +37 -0
  32. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +4 -0
  33. data/lib/jasmine-core/spec/helpers/checkForSet.js +21 -0
  34. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +58 -0
  35. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +1 -1
  36. data/lib/jasmine-core/version.rb +1 -1
  37. metadata +11 -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,476 @@ 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 =
165
+ "Expected [ 1, 2 ] to equal [ 1, 2, 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 involving NaN", function() {
215
+ var actual = {x: 0},
216
+ expected = {x: 0/0},
217
+ message = "Expected $.x = 0 to equal NaN.";
218
+
219
+ expect(compareEquals(actual, expected).message).toEqual(message);
220
+ });
221
+
222
+ it("reports mismatches involving regular expressions", function() {
223
+ var actual = {x: '1'},
224
+ expected = {x: /1/},
225
+ message = "Expected $.x = '1' to equal /1/.";
226
+
227
+ expect(compareEquals(actual, expected).message).toEqual(message);
228
+ });
229
+
230
+ it("reports mismatches involving infinities", function() {
231
+ var actual = {x: 0},
232
+ expected = {x: 1/0},
233
+ message = "Expected $.x = 0 to equal Infinity.";
234
+
235
+ expect(compareEquals(actual, expected).message).toEqual(message);
236
+ });
237
+
238
+ it("reports mismatches involving booleans", function() {
239
+ var actual = {x: false},
240
+ expected = {x: true},
241
+ message = "Expected $.x = false to equal true.";
242
+
243
+ expect(compareEquals(actual, expected).message).toEqual(message);
244
+ });
245
+
246
+ it("reports mismatches involving strings", function() {
247
+ var actual = {x: 'foo'},
248
+ expected = {x: 'bar'},
249
+ message = "Expected $.x = 'foo' to equal 'bar'.";
250
+
251
+ expect(compareEquals(actual, expected).message).toEqual(message);
252
+ });
253
+
254
+ it("reports mismatches involving undefined", function() {
255
+ var actual = {x: void 0},
256
+ expected = {x: 0},
257
+ message = "Expected $.x = undefined to equal 0.";
258
+
259
+ expect(compareEquals(actual, expected).message).toEqual(message);
260
+ });
261
+
262
+ it("reports mismatches involving null", function() {
263
+ var actual = {x: null},
264
+ expected = {x: 0},
265
+ message = "Expected $.x = null to equal 0.";
266
+
267
+ expect(compareEquals(actual, expected).message).toEqual(message);
268
+ });
269
+
270
+ it("reports mismatches between objects with different constructors", function () {
271
+ function Foo() {}
272
+ function Bar() {}
273
+
274
+ var actual = {x: new Foo()},
275
+ expected = {x: new Bar()},
276
+ message = "Expected $.x to be a kind of Bar, but was Foo({ }).";
277
+
278
+ expect(compareEquals(actual, expected).message).toEqual(message);
279
+ });
280
+
281
+ it("reports type mismatches at the root level", function () {
282
+ function Foo() {}
283
+ function Bar() {}
284
+
285
+ var actual = new Foo(),
286
+ expected = new Bar(),
287
+ message = "Expected object to be a kind of Bar, but was Foo({ }).";
288
+
289
+ expect(compareEquals(actual, expected).message).toEqual(message);
290
+ });
291
+
292
+ function constructorIsNotEnumerable() {
293
+ // in IE8, the constructor property is not enumerable, even if it is an
294
+ // own property of the object.
295
+ // Objects that differ only by an own `constructor` property are thus
296
+ // considered equal in IE8.
297
+ for (var key in {constructor: 1}) {
298
+ return false;
299
+ }
300
+ return true;
301
+ }
302
+
303
+ it("reports mismatches between objects with their own constructor property", function () {
304
+ if (constructorIsNotEnumerable()) {
305
+ return;
306
+ }
307
+
308
+ function Foo() {}
309
+ function Bar() {}
310
+
311
+ var actual = {x: {constructor: 'blerf'}},
312
+ expected = {x: {constructor: 'ftarrh'}},
313
+ message = "Expected $.x.constructor = 'blerf' to equal 'ftarrh'.";
314
+
315
+ expect(compareEquals(actual, expected).message).toEqual(message);
316
+ });
317
+
318
+ it("reports mismatches between an object with a real constructor and one with its own constructor property", function () {
319
+ if (constructorIsNotEnumerable()) {
320
+ return;
321
+ }
322
+
323
+ function Foo() {}
324
+ function Bar() {}
325
+
326
+ var actual = {x: {}},
327
+ expected = {x: {constructor: 'ftarrh'}},
328
+ message =
329
+ "Expected $.x to have properties\n" +
330
+ " constructor: 'ftarrh'";
331
+
332
+ expect(compareEquals(actual, expected).message).toEqual(message);
333
+ expect(compareEquals(expected, actual).message).toEqual(
334
+ "Expected $.x not to have properties\n constructor: 'ftarrh'"
335
+ );
336
+ });
337
+
338
+ it("reports mismatches between 0 and -0", function() {
339
+ var actual = {x: 0},
340
+ expected = {x: -0},
341
+ message = "Expected $.x = 0 to equal -0.";
342
+
343
+ expect(compareEquals(actual, expected).message).toEqual(message);
344
+ });
345
+
346
+ it("reports mismatches between Errors", function() {
347
+ var actual = {x: new Error("the error you got")},
348
+ expected = {x: new Error("the error you want")},
349
+ message = "Expected $.x = Error: the error you got to equal Error: the error you want.";
350
+
351
+ expect(compareEquals(actual, expected).message).toEqual(message);
352
+ });
353
+
354
+ it("reports mismatches between Functions", function() {
355
+ var actual = {x: function() {}},
356
+ expected = {x: function() {}},
357
+ message = "Expected $.x = Function to equal Function.";
358
+
359
+ expect(compareEquals(actual, expected).message).toEqual(message);
360
+ });
361
+
362
+ it("does not report deep mismatches within Sets", function() {
363
+ // TODO: implement deep comparison of set elements
364
+ jasmine.getEnv().requireFunctioningSets();
365
+
366
+ var actual = new Set([1]),
367
+ expected = new Set([2]),
368
+ message = 'Expected Set( 1 ) to equal Set( 2 ).';
369
+
370
+ expect(compareEquals(actual, expected).message).toEqual(message);
371
+ });
372
+
373
+ it("reports mismatches between Sets nested in objects", function() {
374
+ jasmine.getEnv().requireFunctioningSets();
375
+
376
+ var actual = {sets: [new Set([1])]},
377
+ expected = {sets: [new Set([2])]},
378
+ message = "Expected $.sets[0] = Set( 1 ) to equal Set( 2 ).";
379
+
380
+ expect(compareEquals(actual, expected).message).toEqual(message);
381
+ });
382
+
383
+ it("reports mismatches between Sets of different lengths", function() {
384
+ jasmine.getEnv().requireFunctioningSets();
385
+
386
+ var actual = new Set([1, 2]),
387
+ expected = new Set([2]),
388
+ message = 'Expected Set( 1, 2 ) to equal Set( 2 ).';
389
+
390
+ expect(compareEquals(actual, expected).message).toEqual(message);
391
+ });
392
+
393
+ function isNotRunningInBrowser() {
394
+ return typeof document === 'undefined'
395
+ }
396
+
397
+ it("reports mismatches between DOM nodes with different tags", function() {
398
+ if(isNotRunningInBrowser()) {
399
+ return;
400
+ }
401
+
402
+ var actual = {a: document.createElement('div')},
403
+ expected = {a: document.createElement('p')},
404
+ message = 'Expected $.a = HTMLNode to equal HTMLNode.';
405
+
406
+ expect(compareEquals(actual, expected).message).toEqual(message);
407
+ });
408
+
409
+ it('reports mismatches between DOM nodes with different content', function() {
410
+ if(isNotRunningInBrowser()) {
411
+ return;
412
+ }
413
+
414
+ var nodeA = document.createElement('div'),
415
+ nodeB = document.createElement('div');
416
+
417
+ nodeA.innerText = 'foo'
418
+ nodeB.innerText = 'bar'
419
+
420
+ var actual = {a: nodeA},
421
+ expected = {a: nodeB},
422
+ message = 'Expected $.a = HTMLNode to equal HTMLNode.';
423
+
424
+ expect(compareEquals(actual, expected).message).toEqual(message);
425
+ })
426
+
427
+ it("reports mismatches between a DOM node and a bare Object", function() {
428
+ if(isNotRunningInBrowser()) {
429
+ return;
430
+ }
431
+
432
+ var actual = {a: document.createElement('div')},
433
+ expected = {a: {}},
434
+ message = 'Expected $.a = HTMLNode to equal Object({ }).';
435
+
436
+ expect(compareEquals(actual, expected).message).toEqual(message);
437
+ });
438
+
439
+ it("reports asymmetric mismatches", function() {
440
+ var actual = {a: 1},
441
+ expected = {a: jasmineUnderTest.any(String)},
442
+ message = 'Expected $.a = 1 to equal <jasmine.any(String)>.';
443
+
444
+ expect(compareEquals(actual, expected).message).toEqual(message);
445
+ expect(compareEquals(actual, expected).pass).toBe(false)
446
+ });
447
+
448
+ it("reports asymmetric mismatches when the asymmetric comparand is the actual value", function() {
449
+ var actual = {a: jasmineUnderTest.any(String)},
450
+ expected = {a: 1},
451
+ message = 'Expected $.a = <jasmine.any(String)> to equal 1.';
452
+
453
+ expect(compareEquals(actual, expected).message).toEqual(message);
454
+ expect(compareEquals(actual, expected).pass).toBe(false)
455
+ });
456
+
457
+ it("does not report a mismatch when asymmetric matchers are satisfied", function() {
458
+ var actual = {a: 'a'},
459
+ expected = {a: jasmineUnderTest.any(String)},
460
+ message = 'Expected $.a = 1 to equal <jasmine.any(String)>.';
461
+
462
+ expect(compareEquals(actual, expected).pass).toBe(true)
463
+ });
464
+
465
+ it("works on big complex stuff", function() {
466
+ var actual = {
467
+ foo: [
468
+ {bar: 1, things: ['a', 'b']},
469
+ {bar: 2, things: ['a', 'b']}
470
+ ],
471
+ baz: [
472
+ {a: {b: 1}}
473
+ ],
474
+ quux: 1,
475
+ nan: 0,
476
+ aRegexp: 'hi',
477
+ inf: -1/0,
478
+ boolean: false,
479
+ notDefined: 0,
480
+ aNull: void 0
481
+ }
482
+
483
+ var expected = {
484
+ foo: [
485
+ {bar: 2, things: ['a', 'b', 'c']},
486
+ {bar: 2, things: ['a', 'd']}
487
+ ],
488
+ baz: [
489
+ {a: {b: 1, c: 1}}
490
+ ],
491
+ quux: [],
492
+ nan: 0/0,
493
+ aRegexp: /hi/,
494
+ inf: 1/0,
495
+ boolean: true,
496
+ notDefined: void 0,
497
+ aNull: null
498
+ }
499
+
500
+ var message =
501
+ 'Expected $.foo[0].bar = 1 to equal 2.\n' +
502
+ "Expected $.foo[0].things = [ 'a', 'b' ] to equal [ 'a', 'b', 'c' ].\n" +
503
+ "Expected $.foo[1].things[1] = 'b' to equal 'd'.\n" +
504
+ 'Expected $.baz[0].a to have properties\n' +
505
+ ' c: 1\n' +
506
+ 'Expected $.quux = 1 to equal [ ].\n' +
507
+ 'Expected $.nan = 0 to equal NaN.\n' +
508
+ "Expected $.aRegexp = 'hi' to equal /hi/.\n" +
509
+ 'Expected $.inf = -Infinity to equal Infinity.\n' +
510
+ 'Expected $.boolean = false to equal true.\n' +
511
+ 'Expected $.notDefined = 0 to equal undefined.\n' +
512
+ 'Expected $.aNull = undefined to equal null.'
513
+
514
+ expect(compareEquals(actual, expected).message).toEqual(message);
515
+ })
28
516
  });
@@ -0,0 +1,99 @@
1
+ describe("toHaveBeenCalledBefore", function() {
2
+ it("throws an exception when the actual is not a spy", function() {
3
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
4
+ fn = function() {},
5
+ secondSpy = jasmineUnderTest.createSpy('second spy');
6
+
7
+ expect(function() { matcher.compare(fn, secondSpy) }).toThrowError(Error, /Expected a spy, but got Function./);
8
+ });
9
+
10
+ it("throws an exception when the expected is not a spy", function() {
11
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
12
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
13
+ fn = function() {};
14
+
15
+ expect(function() { matcher.compare(firstSpy, fn) }).toThrowError(Error, /Expected a spy, but got Function./);
16
+ });
17
+
18
+ it("fails when the actual was not called", function() {
19
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
20
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
21
+ secondSpy = jasmineUnderTest.createSpy('second spy');
22
+
23
+ secondSpy();
24
+
25
+ result = matcher.compare(firstSpy, secondSpy);
26
+ expect(result.pass).toBe(false);
27
+ expect(result.message).toMatch(/Expected spy first spy to have been called./);
28
+ });
29
+
30
+ it("fails when the expected was not called", function() {
31
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
32
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
33
+ secondSpy = jasmineUnderTest.createSpy('second spy');
34
+
35
+ firstSpy();
36
+
37
+ result = matcher.compare(firstSpy, secondSpy);
38
+ expect(result.pass).toBe(false);
39
+ expect(result.message).toMatch(/Expected spy second spy to have been called./);
40
+ });
41
+
42
+ it("fails when the actual is called after the expected", function() {
43
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
44
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
45
+ secondSpy = jasmineUnderTest.createSpy('second spy'),
46
+ result;
47
+
48
+ secondSpy();
49
+ firstSpy();
50
+
51
+ result = matcher.compare(firstSpy, secondSpy);
52
+ expect(result.pass).toBe(false);
53
+ expect(result.message).toEqual('Expected spy first spy to have been called before spy second spy');
54
+ });
55
+
56
+ it("fails when the actual is called before and after the expected", function() {
57
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
58
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
59
+ secondSpy = jasmineUnderTest.createSpy('second spy'),
60
+ result;
61
+
62
+ firstSpy();
63
+ secondSpy();
64
+ firstSpy();
65
+
66
+ result = matcher.compare(firstSpy, secondSpy);
67
+ expect(result.pass).toBe(false);
68
+ expect(result.message).toEqual('Expected latest call to spy first spy to have been called before first call to spy second spy (no interleaved calls)');
69
+ });
70
+
71
+ it("fails when the expected is called before and after the actual", function() {
72
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
73
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
74
+ secondSpy = jasmineUnderTest.createSpy('second spy'),
75
+ result;
76
+
77
+ secondSpy();
78
+ firstSpy();
79
+ secondSpy();
80
+
81
+ result = matcher.compare(firstSpy, secondSpy);
82
+ expect(result.pass).toBe(false);
83
+ expect(result.message).toEqual('Expected first call to spy second spy to have been called after latest call to spy first spy (no interleaved calls)');
84
+ });
85
+
86
+ it("passes when the actual is called before the expected", function() {
87
+ var matcher = jasmineUnderTest.matchers.toHaveBeenCalledBefore(),
88
+ firstSpy = jasmineUnderTest.createSpy('first spy'),
89
+ secondSpy = jasmineUnderTest.createSpy('second spy'),
90
+ result;
91
+
92
+ firstSpy();
93
+ secondSpy();
94
+
95
+ result = matcher.compare(firstSpy, secondSpy);
96
+ expect(result.pass).toBe(true);
97
+ expect(result.message).toEqual('Expected spy first spy to not have been called before spy second spy, but it was');
98
+ });
99
+ });
@@ -65,6 +65,43 @@ describe("toThrowError", function() {
65
65
  expect(result.message()).toEqual("Expected function to throw an Error, but it threw 4.");
66
66
  });
67
67
 
68
+ describe("when error is from another frame", function() {
69
+ function isNotRunningInBrowser() {
70
+ return typeof document === 'undefined'
71
+ }
72
+
73
+ var iframe = null;
74
+
75
+ afterEach(function() {
76
+ if (iframe !== null) {
77
+ document.body.removeChild(iframe);
78
+ }
79
+ });
80
+
81
+ it("passes if thrown is an instanceof Error regardless of global that contains its constructor", function() {
82
+ if (isNotRunningInBrowser() || jasmine.getEnv().phantomVersion < 2 || jasmine.getEnv().ieVersion < 10) {
83
+ return;
84
+ }
85
+
86
+ var matcher = jasmineUnderTest.matchers.toThrowError();
87
+ iframe = document.body.appendChild(document.createElement("iframe"));
88
+ iframe.src = "about:blank";
89
+ var iframeDocument = iframe.contentWindow.document;
90
+
91
+ if (iframeDocument.body) {
92
+ iframeDocument.body.appendChild(iframeDocument.createElement("script"))
93
+ .textContent = "function method() { throw new Error('foo'); }";
94
+ } else {
95
+ // older IE
96
+ iframeDocument.write("<html><head><script>function method() { throw new Error('foo'); }</script></head></html>");
97
+ }
98
+
99
+ var result = matcher.compare(iframe.contentWindow.method);
100
+ expect(result.pass).toBe(true);
101
+ expect(result.message).toEqual("Expected function not to throw an Error, but it threw Error.");
102
+ });
103
+ });
104
+
68
105
  it("fails with the correct message if thrown is a falsy value", function() {
69
106
  var matcher = jasmineUnderTest.matchers.toThrowError(),
70
107
  fn = function() {
@@ -20,4 +20,8 @@
20
20
  return /Firefox\/([0-9]{0,})/.exec(userAgent);
21
21
  });
22
22
 
23
+ env.phantomVersion = browserVersion(function(userAgent) {
24
+ return /PhantomJS\/([0-9]{0,})/.exec(userAgent);
25
+ });
26
+
23
27
  })(jasmine.getEnv());
@@ -0,0 +1,21 @@
1
+ (function(env) {
2
+ function hasFunctioningSets() {
3
+ if (typeof Set === 'undefined') { return false; }
4
+
5
+ try {
6
+ var s = new Set([4]);
7
+ if (s.size !== 1) { return false; }
8
+ if (s.values().next().value !== 4) { return false; }
9
+ return true;
10
+ } catch(e) {
11
+ return false;
12
+ }
13
+ }
14
+
15
+ env.requireFunctioningSets = function() {
16
+ if (!hasFunctioningSets()) {
17
+ env.pending("Browser has incomplete or missing support for Sets");
18
+ }
19
+ };
20
+
21
+ })(jasmine.getEnv());