rally-jasmine-core 1.2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/lib/jasmine-core.rb +36 -0
  2. data/lib/jasmine-core/example/SpecRunner.html +54 -0
  3. data/lib/jasmine-core/example/spec/PlayerSpec.js +58 -0
  4. data/lib/jasmine-core/example/spec/SpecHelper.js +9 -0
  5. data/lib/jasmine-core/example/src/Player.js +22 -0
  6. data/lib/jasmine-core/example/src/Song.js +7 -0
  7. data/lib/jasmine-core/jasmine-html.js +681 -0
  8. data/lib/jasmine-core/jasmine.css +82 -0
  9. data/lib/jasmine-core/jasmine.js +2568 -0
  10. data/lib/jasmine-core/json2.js +478 -0
  11. data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +451 -0
  12. data/lib/jasmine-core/spec/core/BaseSpec.js +27 -0
  13. data/lib/jasmine-core/spec/core/CustomMatchersSpec.js +97 -0
  14. data/lib/jasmine-core/spec/core/EnvSpec.js +159 -0
  15. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +175 -0
  16. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +103 -0
  17. data/lib/jasmine-core/spec/core/MatchersSpec.js +1145 -0
  18. data/lib/jasmine-core/spec/core/MockClockSpec.js +38 -0
  19. data/lib/jasmine-core/spec/core/MultiReporterSpec.js +45 -0
  20. data/lib/jasmine-core/spec/core/NestedResultsSpec.js +54 -0
  21. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +94 -0
  22. data/lib/jasmine-core/spec/core/QueueSpec.js +23 -0
  23. data/lib/jasmine-core/spec/core/ReporterSpec.js +56 -0
  24. data/lib/jasmine-core/spec/core/RunnerSpec.js +280 -0
  25. data/lib/jasmine-core/spec/core/SpecRunningSpec.js +1291 -0
  26. data/lib/jasmine-core/spec/core/SpecSpec.js +124 -0
  27. data/lib/jasmine-core/spec/core/SpySpec.js +216 -0
  28. data/lib/jasmine-core/spec/core/SuiteSpec.js +120 -0
  29. data/lib/jasmine-core/spec/core/UtilSpec.js +39 -0
  30. data/lib/jasmine-core/spec/core/WaitsForBlockSpec.js +118 -0
  31. data/lib/jasmine-core/spec/html/HTMLReporterSpec.js +209 -0
  32. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +38 -0
  33. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +8 -0
  34. data/lib/jasmine-core/spec/html/TrivialReporterSpec.js +239 -0
  35. data/lib/jasmine-core/spec/node_suite.js +127 -0
  36. data/lib/jasmine-core/version.rb +6 -0
  37. metadata +288 -0
@@ -0,0 +1,1145 @@
1
+ describe("jasmine.Matchers", function() {
2
+ var env, spec;
3
+
4
+ beforeEach(function() {
5
+ env = new jasmine.Env();
6
+ env.updateInterval = 0;
7
+
8
+ var suite = env.describe("suite", function() {
9
+ spec = env.it("spec", function() {
10
+ });
11
+ });
12
+ spyOn(spec, 'addMatcherResult');
13
+
14
+ this.addMatchers({
15
+ toPass: function() {
16
+ return lastResult().passed();
17
+ },
18
+ toFail: function() {
19
+ return !lastResult().passed();
20
+ }
21
+ });
22
+ });
23
+
24
+ function match(value) {
25
+ return spec.expect(value);
26
+ }
27
+
28
+ function lastResult() {
29
+ return spec.addMatcherResult.mostRecentCall.args[0];
30
+ }
31
+
32
+ function catchException(fn) {
33
+ try {
34
+ fn.call();
35
+ } catch (e) {
36
+ return e;
37
+ }
38
+ throw new Error("expected function to throw an exception");
39
+ }
40
+
41
+ it("toEqual with primitives, objects, dates, etc.", function() {
42
+ expect(match(true).toEqual(true)).toPass();
43
+
44
+ expect(match({foo:'bar'}).toEqual(null)).toFail();
45
+
46
+ var functionA = function() {
47
+ return 'hi';
48
+ };
49
+ var functionB = function() {
50
+ return 'hi';
51
+ };
52
+ expect(match({foo:functionA}).toEqual({foo:functionB})).toFail();
53
+ expect(match({foo:functionA}).toEqual({foo:functionA})).toPass();
54
+
55
+ expect((match(false).toEqual(true))).toFail();
56
+
57
+ var circularGraph = {};
58
+ circularGraph.referenceToSelf = circularGraph;
59
+ expect((match(circularGraph).toEqual(circularGraph))).toPass();
60
+
61
+ expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2009, 1, 3, 15, 17, 19, 1234)))).toFail();
62
+ expect((match(new Date(2008, 1, 3, 15, 17, 19, 1234)).toEqual(new Date(2008, 1, 3, 15, 17, 19, 1234)))).toPass();
63
+
64
+
65
+ expect(match(true).toNotEqual(false)).toPass();
66
+ expect((match(true).toNotEqual(true))).toFail();
67
+
68
+ expect((match(['a', 'b']).toEqual(['a', jasmine.undefined]))).toFail();
69
+ expect((match(['a', 'b']).toEqual(['a', 'b', jasmine.undefined]))).toFail();
70
+
71
+ expect((match("cat").toEqual("cat"))).toPass();
72
+ expect((match("cat").toNotEqual("cat"))).toFail();
73
+
74
+ expect((match(5).toEqual(5))).toPass();
75
+ expect((match(parseInt('5', 10)).toEqual(5))).toPass();
76
+ expect((match(5).toNotEqual(5))).toFail();
77
+ expect((match(parseInt('5', 10)).toNotEqual(5))).toFail();
78
+ });
79
+
80
+ it("toEqual to build an Expectation Result", function() {
81
+ var actual = 'a';
82
+ var matcher = match(actual);
83
+ var expected = 'b';
84
+ matcher.toEqual(expected);
85
+
86
+ var result = lastResult();
87
+
88
+ expect(result.matcherName).toEqual("toEqual");
89
+ expect(result.passed()).toFail();
90
+ expect(result.message).toMatch(jasmine.pp(actual));
91
+ expect(result.message).toMatch(jasmine.pp(expected));
92
+ expect(result.expected).toEqual(expected);
93
+ expect(result.actual).toEqual(actual);
94
+ });
95
+
96
+ it("toNotEqual to build an Expectation Result", function() {
97
+ var str = 'a';
98
+ var matcher = match(str);
99
+ matcher.toNotEqual(str);
100
+
101
+ var result = lastResult();
102
+
103
+ expect(result.matcherName).toEqual("toNotEqual");
104
+ expect(result.passed()).toFail();
105
+ expect(result.message).toMatch(jasmine.pp(str));
106
+ expect(result.message).toMatch('not');
107
+ expect(result.expected).toEqual(str);
108
+ expect(result.actual).toEqual(str);
109
+ });
110
+
111
+ it('toBe should return true only if the expected and actual items === each other', function() {
112
+ var a = {};
113
+ var b = {};
114
+ //noinspection UnnecessaryLocalVariableJS
115
+ var c = a;
116
+ expect((match(a).toBe(b))).toFail();
117
+ expect((match(a).toBe(a))).toPass();
118
+ expect((match(a).toBe(c))).toPass();
119
+ expect((match(a).toNotBe(b))).toPass();
120
+ expect((match(a).toNotBe(a))).toFail();
121
+ expect((match(a).toNotBe(c))).toFail();
122
+ });
123
+
124
+ it("toBe to build an ExpectationResult", function() {
125
+ var expected = 'b';
126
+ var actual = 'a';
127
+ var matcher = match(actual);
128
+ matcher.toBe(expected);
129
+
130
+ var result = lastResult();
131
+
132
+ expect(result.matcherName).toEqual("toBe");
133
+ expect(result.passed()).toFail();
134
+ expect(result.message).toMatch(jasmine.pp(actual));
135
+ expect(result.message).toMatch(jasmine.pp(expected));
136
+ expect(result.expected).toEqual(expected);
137
+ expect(result.actual).toEqual(actual);
138
+ });
139
+
140
+ it("toNotBe to build an ExpectationResult", function() {
141
+ var str = 'a';
142
+ var matcher = match(str);
143
+ matcher.toNotBe(str);
144
+
145
+ var result = lastResult();
146
+
147
+ expect(result.matcherName).toEqual("toNotBe");
148
+ expect(result.passed()).toFail();
149
+ expect(result.message).toMatch(str);
150
+ expect(result.expected).toEqual(str);
151
+ expect(result.actual).toEqual(str);
152
+ });
153
+
154
+ it("toMatch and #toNotMatch should perform regular expression matching on strings", function() {
155
+ expect((match('foobarbel').toMatch(/bar/))).toPass();
156
+ expect((match('foobazbel').toMatch(/bar/))).toFail();
157
+
158
+ expect((match('foobarbel').toMatch("bar"))).toPass();
159
+ expect((match('foobazbel').toMatch("bar"))).toFail();
160
+
161
+ expect((match('foobarbel').toNotMatch(/bar/))).toFail();
162
+ expect((match('foobazbel').toNotMatch(/bar/))).toPass();
163
+
164
+ expect((match('foobarbel').toNotMatch("bar"))).toFail();
165
+ expect((match('foobazbel').toNotMatch("bar"))).toPass();
166
+ });
167
+
168
+ it("toMatch w/ RegExp to build an ExpectationResult", function() {
169
+ var actual = 'a';
170
+ var matcher = match(actual);
171
+ var expected = /b/;
172
+ matcher.toMatch(expected);
173
+
174
+ var result = lastResult();
175
+
176
+ expect(result.matcherName).toEqual("toMatch");
177
+ expect(result.passed()).toFail();
178
+ expect(result.message).toMatch(jasmine.pp(actual));
179
+ expect(result.message).toMatch(expected.toString());
180
+ expect(result.expected).toEqual(expected);
181
+ expect(result.actual).toEqual(actual);
182
+ });
183
+
184
+ it("toMatch w/ String to build an ExpectationResult", function() {
185
+ var actual = 'a';
186
+ var matcher = match(actual);
187
+ var expected = 'b';
188
+ matcher.toMatch(expected);
189
+
190
+ var result = lastResult();
191
+
192
+ expect(result.matcherName).toEqual("toMatch");
193
+ expect(result.passed()).toFail();
194
+ expect(result.message).toEqual("Expected 'a' to match 'b'.");
195
+ expect(result.expected).toEqual(expected);
196
+ expect(result.actual).toEqual(actual);
197
+ });
198
+
199
+ it("toNotMatch w/ RegExp to build an ExpectationResult", function() {
200
+ var actual = 'a';
201
+ var matcher = match(actual);
202
+ var expected = /a/;
203
+ matcher.toNotMatch(expected);
204
+
205
+ var result = lastResult();
206
+
207
+ expect(result.matcherName).toEqual("toNotMatch");
208
+ expect(result.passed()).toFail();
209
+ expect(result.message).toEqual("Expected 'a' to not match /a/.");
210
+ expect(result.expected).toEqual(expected);
211
+ expect(result.actual).toEqual(actual);
212
+ });
213
+
214
+ it("toNotMatch w/ String to build an ExpectationResult", function() {
215
+ var str = 'a';
216
+ var matcher = match(str);
217
+ matcher.toNotMatch(str);
218
+
219
+ var result = lastResult();
220
+
221
+ expect(result.matcherName).toEqual("toNotMatch");
222
+ expect(result.passed()).toFail();
223
+ expect(result.message).toEqual("Expected 'a' to not match 'a'.");
224
+ expect(result.expected).toEqual(str);
225
+ expect(result.actual).toEqual(str);
226
+ });
227
+
228
+ it("toBeDefined", function() {
229
+ expect(match('foo').toBeDefined()).toPass();
230
+ expect(match(jasmine.undefined).toBeDefined()).toFail();
231
+ });
232
+
233
+ it("toBeDefined to build an ExpectationResult", function() {
234
+ var matcher = match(jasmine.undefined);
235
+ matcher.toBeDefined();
236
+
237
+ var result = lastResult();
238
+
239
+ expect(result.matcherName).toEqual("toBeDefined");
240
+ expect(result.passed()).toFail();
241
+ expect(result.message).toEqual('Expected undefined to be defined.');
242
+ expect(result.actual).toEqual(jasmine.undefined);
243
+ });
244
+
245
+ it("toBeUndefined", function() {
246
+ expect(match('foo').toBeUndefined()).toFail();
247
+ expect(match(jasmine.undefined).toBeUndefined()).toPass();
248
+ });
249
+
250
+ it("toBeNull", function() {
251
+ expect(match(null).toBeNull()).toPass();
252
+ expect(match(jasmine.undefined).toBeNull()).toFail();
253
+ expect(match("foo").toBeNull()).toFail();
254
+ });
255
+
256
+ it("toBeNull w/ String to build an ExpectationResult", function() {
257
+ var actual = 'a';
258
+ var matcher = match(actual);
259
+ matcher.toBeNull();
260
+
261
+ var result = lastResult();
262
+
263
+ expect(result.matcherName).toEqual("toBeNull");
264
+ expect(result.passed()).toFail();
265
+ expect(result.message).toMatch(jasmine.pp(actual));
266
+ expect(result.message).toMatch('null');
267
+ expect(result.actual).toEqual(actual);
268
+ });
269
+
270
+ it("toBeNull w/ Object to build an ExpectationResult", function() {
271
+ var actual = {a: 'b'};
272
+ var matcher = match(actual);
273
+ matcher.toBeNull();
274
+
275
+ var result = lastResult();
276
+
277
+ expect(result.matcherName).toEqual("toBeNull");
278
+ expect(result.passed()).toFail();
279
+ expect(result.message).toMatch(jasmine.pp(actual));
280
+ expect(result.message).toMatch('null');
281
+ expect(result.actual).toEqual(actual);
282
+ });
283
+
284
+ it("toBeNaN", function() {
285
+ expect(match(Number.NaN).toBeNaN()).toPass();
286
+ expect(match(0).toBeNaN()).toFail();
287
+ expect(match(1).toBeNaN()).toFail();
288
+ expect(match(null).toBeNaN()).toFail();
289
+ expect(match(Number.POSITIVE_INFINITY).toBeNaN()).toFail();
290
+ expect(match(Number.NEGATIVE_INFINITY).toBeNaN()).toFail();
291
+ expect(match('NaN').toBeNaN()).toFail();
292
+ });
293
+
294
+ it("toBeNaN to build an ExpectationResult", function() {
295
+ var actual = 'a';
296
+ var matcher = match(actual);
297
+ matcher.toBeNaN();
298
+
299
+ var result = lastResult();
300
+
301
+ expect(result.matcherName).toEqual("toBeNaN");
302
+ expect(result.passed()).toFail();
303
+ expect(result.message).toMatch("Expected 'a' to be NaN.");
304
+ expect(result.actual).toMatch(actual);
305
+ });
306
+
307
+ it("toBeFalsy", function() {
308
+ expect(match(false).toBeFalsy()).toPass();
309
+ expect(match(true).toBeFalsy()).toFail();
310
+ expect(match(jasmine.undefined).toBeFalsy()).toPass();
311
+ expect(match(0).toBeFalsy()).toPass();
312
+ expect(match("").toBeFalsy()).toPass();
313
+ });
314
+
315
+ it("toBeFalsy to build an ExpectationResult", function() {
316
+ var actual = 'a';
317
+ var matcher = match(actual);
318
+ matcher.toBeFalsy();
319
+
320
+ var result = lastResult();
321
+
322
+ expect(result.matcherName).toEqual("toBeFalsy");
323
+ expect(result.passed()).toFail();
324
+ expect(result.message).toMatch(jasmine.pp(actual));
325
+ expect(result.message).toMatch('falsy');
326
+ expect(result.actual).toEqual(actual);
327
+ });
328
+
329
+ it("toBeTruthy", function() {
330
+ expect(match(false).toBeTruthy()).toFail();
331
+ expect(match(true).toBeTruthy()).toPass();
332
+ expect(match(jasmine.undefined).toBeTruthy()).toFail();
333
+ expect(match(0).toBeTruthy()).toFail();
334
+ expect(match("").toBeTruthy()).toFail();
335
+ expect(match("hi").toBeTruthy()).toPass();
336
+ expect(match(5).toBeTruthy()).toPass();
337
+ expect(match({foo: 1}).toBeTruthy()).toPass();
338
+ });
339
+
340
+ it("toBeTruthy to build an ExpectationResult", function() {
341
+ var matcher = match(false);
342
+ matcher.toBeTruthy();
343
+
344
+ var result = lastResult();
345
+
346
+ expect(result.matcherName).toEqual("toBeTruthy");
347
+ expect(result.passed()).toFail();
348
+ expect(result.message).toEqual("Expected false to be truthy.");
349
+ expect(result.actual).toFail();
350
+ });
351
+
352
+ it("toEqual", function() {
353
+ expect(match(jasmine.undefined).toEqual(jasmine.undefined)).toPass();
354
+ expect(match({foo:'bar'}).toEqual({foo:'bar'})).toPass();
355
+ expect(match("foo").toEqual({bar: jasmine.undefined})).toFail();
356
+ expect(match({foo: jasmine.undefined}).toEqual("goo")).toFail();
357
+ expect(match({foo: {bar :jasmine.undefined}}).toEqual("goo")).toFail();
358
+ });
359
+
360
+ it("toEqual with jasmine.any()", function() {
361
+ expect(match("foo").toEqual(jasmine.any(String))).toPass();
362
+ expect(match(3).toEqual(jasmine.any(Number))).toPass();
363
+ expect(match("foo").toEqual(jasmine.any(Function))).toFail();
364
+ expect(match("foo").toEqual(jasmine.any(Object))).toFail();
365
+ expect(match({someObj:'foo'}).toEqual(jasmine.any(Object))).toPass();
366
+ expect(match({someObj:'foo'}).toEqual(jasmine.any(Function))).toFail();
367
+ expect(match(
368
+ function() {
369
+ }).toEqual(jasmine.any(Object))).toFail();
370
+ expect(match(["foo", "goo"]).toEqual(["foo", jasmine.any(String)])).toPass();
371
+ expect(match(
372
+ function() {
373
+ }).toEqual(jasmine.any(Function))).toPass();
374
+ expect(match(["a", function() {
375
+ }]).toEqual(["a", jasmine.any(Function)])).toPass();
376
+ });
377
+
378
+ describe("toEqual with an object implementing jasmineMatches", function () {
379
+ var matcher;
380
+ beforeEach(function () {
381
+ matcher = {
382
+ jasmineMatches: jasmine.createSpy("jasmineMatches")
383
+ };
384
+ });
385
+
386
+ describe("on the left side", function () {
387
+ it("uses the jasmineMatches function", function () {
388
+ matcher.jasmineMatches.andReturn(false);
389
+ expect(match(matcher).toEqual("foo")).toFail();
390
+ matcher.jasmineMatches.andReturn(true);
391
+ expect(match(matcher).toEqual("foo")).toPass();
392
+ });
393
+ });
394
+
395
+ describe("on the right side", function () {
396
+ it("uses the jasmineMatches function", function () {
397
+ matcher.jasmineMatches.andReturn(false);
398
+ expect(match("foo").toEqual(matcher)).toFail();
399
+ matcher.jasmineMatches.andReturn(true);
400
+ expect(match("foo").toEqual(matcher)).toPass();
401
+ });
402
+ });
403
+ });
404
+
405
+ it("toEqual handles circular objects ok", function() {
406
+ expect(match({foo: "bar", baz: jasmine.undefined}).toEqual({foo: "bar", baz: jasmine.undefined})).toPass();
407
+ expect(match({foo:['bar','baz','quux']}).toEqual({foo:['bar','baz','quux']})).toPass();
408
+ expect(match({foo: {bar:'baz'}, quux:'corge'}).toEqual({foo:{bar:'baz'}, quux:'corge'})).toPass();
409
+
410
+ var circularObject = {};
411
+ var secondCircularObject = {};
412
+ circularObject.field = circularObject;
413
+ secondCircularObject.field = secondCircularObject;
414
+ expect(match(circularObject).toEqual(secondCircularObject)).toPass();
415
+ });
416
+
417
+ it("toNotEqual as slightly surprising behavior, but is it intentional?", function() {
418
+ expect(match({x:"x", y:"y", z:"w"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
419
+ expect(match({x:"x", y:"y", w:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
420
+ expect(match({x:"x", y:"y", z:"z"}).toNotEqual({w: "w", x:"x", y:"y", z:"z"})).toPass();
421
+ expect(match({w: "w", x:"x", y:"y", z:"z"}).toNotEqual({x:"x", y:"y", z:"z"})).toPass();
422
+ });
423
+
424
+ it("toEqual handles arrays", function() {
425
+ expect(match([1, "A"]).toEqual([1, "A"])).toPass();
426
+ });
427
+
428
+ it("toContain and toNotContain", function() {
429
+ expect(match('ABC').toContain('A')).toPass();
430
+ expect(match('ABC').toContain('X')).toFail();
431
+
432
+ expect(match(['A', 'B', 'C']).toContain('A')).toPass();
433
+ expect(match(['A', 'B', 'C']).toContain('F')).toFail();
434
+ expect(match(['A', 'B', 'C']).toNotContain('F')).toPass();
435
+ expect(match(['A', 'B', 'C']).toNotContain('A')).toFail();
436
+
437
+ expect(match(['A', {some:'object'}, 'C']).toContain({some:'object'})).toPass();
438
+ expect(match(['A', {some:'object'}, 'C']).toContain({some:'other object'})).toFail();
439
+ });
440
+
441
+ it("toContain to build an ExpectationResult", function() {
442
+ var actual = ['a','b','c'];
443
+ var matcher = match(actual);
444
+ var expected = 'x';
445
+ matcher.toContain(expected);
446
+
447
+ var result = lastResult();
448
+
449
+ expect(result.matcherName).toEqual("toContain");
450
+ expect(result.passed()).toFail();
451
+ expect(result.message).toMatch(jasmine.pp(actual));
452
+ expect(result.message).toMatch('contain');
453
+ expect(result.message).toMatch(jasmine.pp(expected));
454
+ expect(result.actual).toEqual(actual);
455
+ expect(result.expected).toEqual(expected);
456
+ });
457
+
458
+ it("toNotContain to build an ExpectationResult", function() {
459
+ var actual = ['a','b','c'];
460
+ var matcher = match(actual);
461
+ var expected = 'b';
462
+ matcher.toNotContain(expected);
463
+
464
+ var result = lastResult();
465
+
466
+ expect(result.matcherName).toEqual("toNotContain");
467
+ expect(result.passed()).toFail();
468
+ expect(result.message).toMatch(jasmine.pp(actual));
469
+ expect(result.message).toMatch('not contain');
470
+ expect(result.message).toMatch(jasmine.pp(expected));
471
+ expect(result.actual).toEqual(actual);
472
+ expect(result.expected).toEqual(expected);
473
+ });
474
+
475
+ it("toBeLessThan should pass if actual is less than expected", function() {
476
+ expect(match(37).toBeLessThan(42)).toPass();
477
+ expect(match(37).toBeLessThan(-42)).toFail();
478
+ expect(match(37).toBeLessThan(37)).toFail();
479
+ });
480
+
481
+ it("toBeLessThan to build an ExpectationResult", function() {
482
+ var actual = 3;
483
+ var matcher = match(actual);
484
+ var expected = 1;
485
+ matcher.toBeLessThan(expected);
486
+
487
+ var result = lastResult();
488
+
489
+ expect(result.matcherName).toEqual("toBeLessThan");
490
+ expect(result.passed()).toFail();
491
+ expect(result.message).toMatch(jasmine.pp(actual) + ' to be less than');
492
+ expect(result.message).toMatch(jasmine.pp(expected));
493
+ expect(result.actual).toEqual(actual);
494
+ expect(result.expected).toEqual(expected);
495
+ });
496
+
497
+ it("toBeGreaterThan should pass if actual is greater than expected", function() {
498
+ expect(match(37).toBeGreaterThan(42)).toFail();
499
+ expect(match(37).toBeGreaterThan(-42)).toPass();
500
+ expect(match(37).toBeGreaterThan(37)).toFail();
501
+ });
502
+
503
+ it("toBeGreaterThan to build an ExpectationResult", function() {
504
+ var actual = 1;
505
+ var matcher = match(actual);
506
+ var expected = 3;
507
+ matcher.toBeGreaterThan(expected);
508
+
509
+ var result = lastResult();
510
+
511
+ expect(result.matcherName).toEqual("toBeGreaterThan");
512
+ expect(result.passed()).toFail();
513
+ expect(result.message).toMatch(jasmine.pp(actual) + ' to be greater than');
514
+ expect(result.message).toMatch(jasmine.pp(expected));
515
+ expect(result.actual).toEqual(actual);
516
+ expect(result.expected).toEqual(expected);
517
+ });
518
+
519
+ describe("toBeCloseTo", function() {
520
+ it("returns 'true' iff actual and expected are equal within 2 decimal points of precision", function() {
521
+ expect(0).toBeCloseTo(0);
522
+ expect(1).toBeCloseTo(1);
523
+ expect(1).not.toBeCloseTo(1.1);
524
+ expect(1).not.toBeCloseTo(1.01);
525
+ expect(1).toBeCloseTo(1.001);
526
+
527
+ expect(1.23).toBeCloseTo(1.234);
528
+ expect(1.23).toBeCloseTo(1.233);
529
+ expect(1.23).toBeCloseTo(1.232);
530
+ expect(1.23).not.toBeCloseTo(1.24);
531
+
532
+ expect(-1.23).toBeCloseTo(-1.234);
533
+ expect(-1.23).not.toBeCloseTo(-1.24);
534
+ });
535
+
536
+ it("expects close numbers to 'be close' and further numbers not to", function() {
537
+ expect(1.225).not.toBeCloseTo(1.234); // difference is 0.009
538
+ expect(1.225).toBeCloseTo(1.224); // difference is 0.001
539
+ });
540
+
541
+ it("accepts an optional precision argument", function() {
542
+ expect(1).toBeCloseTo(1.1, 0);
543
+ expect(1.2).toBeCloseTo(1.23, 1);
544
+
545
+ expect(1.234).toBeCloseTo(1.2343, 3);
546
+ expect(1.234).not.toBeCloseTo(1.233, 3);
547
+ });
548
+
549
+ it("rounds", function() {
550
+ expect(1.23).toBeCloseTo(1.229);
551
+ expect(1.23).toBeCloseTo(1.226);
552
+ expect(1.23).toBeCloseTo(1.225);
553
+ expect(1.23).not.toBeCloseTo(1.2249999);
554
+
555
+ expect(1.23).toBeCloseTo(1.234);
556
+ expect(1.23).toBeCloseTo(1.2349999);
557
+ expect(1.23).not.toBeCloseTo(1.235);
558
+
559
+ expect(-1.23).toBeCloseTo(-1.234);
560
+ expect(-1.23).not.toBeCloseTo(-1.235);
561
+ expect(-1.23).not.toBeCloseTo(-1.236);
562
+ });
563
+ });
564
+
565
+ describe("toThrow", function() {
566
+ describe("when code block throws an exception", function() {
567
+ var throwingFn;
568
+
569
+ beforeEach(function() {
570
+ throwingFn = function() {
571
+ throw new Error("Fake Error");
572
+ };
573
+ });
574
+
575
+ it("should match any exception", function() {
576
+ expect(match(throwingFn).toThrow()).toPass();
577
+ });
578
+
579
+ it("should match exceptions specified by message", function() {
580
+ expect(match(throwingFn).toThrow("Fake Error")).toPass();
581
+ expect(match(throwingFn).toThrow("Other Error")).toFail();
582
+ expect(lastResult().message).toMatch("Other Error");
583
+ });
584
+
585
+ it("should match exceptions specified by Error", function() {
586
+ expect(match(throwingFn).toThrow(new Error("Fake Error"))).toPass();
587
+ expect(match(throwingFn).toThrow(new Error("Other Error"))).toFail();
588
+ expect(lastResult().message).toMatch("Other Error");
589
+ });
590
+
591
+ describe("and matcher is inverted with .not", function() {
592
+ it("should match any exception", function() {
593
+ expect(match(throwingFn).not.toThrow()).toFail();
594
+ expect(lastResult().message).toMatch(/Expected function not to throw an exception/);
595
+ });
596
+
597
+ it("should match exceptions specified by message", function() {
598
+ expect(match(throwingFn).not.toThrow("Fake Error")).toFail();
599
+ // expect(lastResult().message).toMatch(/Expected function not to throw Fake Error./);
600
+ expect(match(throwingFn).not.toThrow("Other Error")).toPass();
601
+ });
602
+
603
+ it("should match exceptions specified by Error", function() {
604
+ expect(match(throwingFn).not.toThrow(new Error("Fake Error"))).toFail();
605
+ // expect(lastResult().message).toMatch("Other Error");
606
+ expect(match(throwingFn).not.toThrow(new Error("Other Error"))).toPass();
607
+ });
608
+ });
609
+ });
610
+
611
+ describe("when actual is not a function", function() {
612
+ it("should fail with an exception", function() {
613
+ var exception = catchException(function() {
614
+ match('not-a-function').toThrow();
615
+ });
616
+ expect(exception).toBeDefined();
617
+ expect(exception.message).toEqual('Actual is not a function');
618
+ });
619
+
620
+ describe("and matcher is inverted with .not", function() {
621
+ it("should fail with an exception", function() {
622
+ var exception = catchException(function() {
623
+ match('not-a-function').not.toThrow();
624
+ });
625
+ expect(exception).toBeDefined();
626
+ expect(exception.message).toEqual('Actual is not a function');
627
+ });
628
+ });
629
+ });
630
+
631
+
632
+ describe("when code block does not throw an exception", function() {
633
+ it("should fail (or pass when inverted with .not)", function() {
634
+ expect(match(
635
+ function() {
636
+ }).toThrow()).toFail();
637
+ expect(lastResult().message).toEqual('Expected function to throw an exception.');
638
+ });
639
+ });
640
+ });
641
+
642
+ describe(".not.matcher", function() {
643
+ it("should invert the sense of any matcher", function() {
644
+ expect(match(37).not.toBeGreaterThan(42)).toPass();
645
+ expect(match(42).not.toBeGreaterThan(37)).toFail();
646
+ expect(match("abc").not.toEqual("def")).toPass();
647
+ expect(match("abc").not.toEqual("abc")).toFail();
648
+ });
649
+
650
+ it("should provide an inverted default message", function() {
651
+ match(37).not.toBeGreaterThan(42);
652
+ expect(lastResult().message).toEqual("Passed.");
653
+
654
+ match(42).not.toBeGreaterThan(37);
655
+ expect(lastResult().message).toEqual("Expected 42 not to be greater than 37.");
656
+ });
657
+
658
+ it("should use the second message when the matcher sets an array of custom messages", function() {
659
+ spec.addMatchers({
660
+ custom: function() {
661
+ this.message = function() {
662
+ return ['Expected it was called.', 'Expected it wasn\'t called.'];
663
+ };
664
+ return this.actual;
665
+ }
666
+ });
667
+
668
+ match(true).custom();
669
+ expect(lastResult().message).toEqual("Passed.");
670
+ match(false).custom();
671
+ expect(lastResult().message).toEqual("Expected it was called.");
672
+ match(true).not.custom();
673
+ expect(lastResult().message).toEqual("Expected it wasn't called.");
674
+ match(false).not.custom();
675
+ expect(lastResult().message).toEqual("Passed.");
676
+ });
677
+ });
678
+
679
+ describe("spy matchers >>", function() {
680
+ var TestClass;
681
+ beforeEach(function() {
682
+ TestClass = {
683
+ normalFunction: function() {
684
+ },
685
+ spyFunction: jasmine.createSpy("My spy")
686
+ };
687
+ });
688
+
689
+ function shouldThrowAnExceptionWhenInvokedOnANonSpy(methodName) {
690
+ return function() {
691
+ expect(
692
+ function() {
693
+ match(TestClass.normalFunction)[methodName]();
694
+ }).toThrow('Expected a spy, but got Function.');
695
+
696
+ expect(
697
+ function() {
698
+ match(jasmine.undefined)[methodName]();
699
+ }).toThrow('Expected a spy, but got undefined.');
700
+
701
+ expect(
702
+ function() {
703
+ match({some:'object'})[methodName]();
704
+ }).toThrow('Expected a spy, but got { some : \'object\' }.');
705
+
706
+ expect(
707
+ function() {
708
+ match("<b>")[methodName]();
709
+ }).toThrow('Expected a spy, but got \'<b>\'.');
710
+ };
711
+ }
712
+
713
+ describe("toHaveBeenCalled", function() {
714
+ it("should pass if the spy was called", function() {
715
+ expect(match(TestClass.spyFunction).toHaveBeenCalled()).toFail();
716
+
717
+ TestClass.spyFunction();
718
+ expect(match(TestClass.spyFunction).toHaveBeenCalled()).toPass();
719
+ });
720
+
721
+ it("should throw an exception when invoked with any arguments", function() {
722
+ expect(
723
+ function() {
724
+ match(TestClass.normalFunction).toHaveBeenCalled("unwanted argument");
725
+ }).toThrow('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
726
+ });
727
+
728
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalled'));
729
+ });
730
+
731
+ describe("wasCalled", function() {
732
+ it("should alias toHaveBeenCalled", function() {
733
+ spyOn(TestClass, 'normalFunction');
734
+
735
+ TestClass.normalFunction();
736
+
737
+ expect(TestClass.normalFunction).wasCalled();
738
+ });
739
+ });
740
+
741
+
742
+ describe("wasNotCalled", function() {
743
+ it("should pass iff the spy was not called", function() {
744
+ expect(match(TestClass.spyFunction).wasNotCalled()).toPass();
745
+
746
+ TestClass.spyFunction();
747
+ expect(match(TestClass.spyFunction).wasNotCalled()).toFail();
748
+ });
749
+
750
+ it("should throw an exception when invoked with any arguments", function() {
751
+ expect(
752
+ function() {
753
+ match(TestClass.normalFunction).wasNotCalled("unwanted argument");
754
+ }).toThrow('wasNotCalled does not take arguments');
755
+ });
756
+
757
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalled'));
758
+ });
759
+
760
+ describe("toHaveBeenCalledWith", function() {
761
+ it('toHaveBeenCalledWith should return true if it was called with the expected args', function() {
762
+ TestClass.spyFunction('a', 'b', 'c');
763
+ expect(match(TestClass.spyFunction).toHaveBeenCalledWith('a', 'b', 'c')).toPass();
764
+ });
765
+
766
+ it('should return false if it was not called with the expected args', function() {
767
+ TestClass.spyFunction('a', 'b', 'c');
768
+ var expected = match(TestClass.spyFunction);
769
+ expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
770
+ var result = lastResult();
771
+ expect(result.passed()).toFail();
772
+ expect(result.expected).toEqual(['c', 'b', 'a']);
773
+ expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
774
+ expect(result.message).toContain(jasmine.pp(result.expected));
775
+ expect(result.message).toContain(jasmine.pp(result.actual.mostRecentCall.args));
776
+ });
777
+
778
+ it('should return false if it was not called', function() {
779
+ var expected = match(TestClass.spyFunction);
780
+ expect(expected.toHaveBeenCalledWith('c', 'b', 'a')).toFail();
781
+ var result = lastResult();
782
+ expect(result.passed()).toFail();
783
+ expect(result.expected).toEqual(['c', 'b', 'a']);
784
+ expect(result.actual.argsForCall).toEqual([]);
785
+ expect(result.message).toContain(jasmine.pp(result.expected));
786
+ });
787
+
788
+ it('should allow matches across multiple calls', function() {
789
+ TestClass.spyFunction('a', 'b', 'c');
790
+ TestClass.spyFunction('d', 'e', 'f');
791
+ var expected = match(TestClass.spyFunction);
792
+ expect(expected.toHaveBeenCalledWith('a', 'b', 'c')).toPass();
793
+ expect(expected.toHaveBeenCalledWith('d', 'e', 'f')).toPass();
794
+ expect(expected.toHaveBeenCalledWith('x', 'y', 'z')).toFail();
795
+ });
796
+
797
+ it("should return a decent message", function() {
798
+ TestClass.spyFunction('a', 'b', 'c');
799
+ TestClass.spyFunction('d', 'e', 'f');
800
+ var expected = match(TestClass.spyFunction);
801
+ expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
802
+ expect(lastResult().message).toEqual("Expected spy My spy to have been called with [ 'a', 'b' ] but actual calls were [ 'a', 'b', 'c' ], [ 'd', 'e', 'f' ]");
803
+ });
804
+
805
+ it("should return a decent message when it hasn't been called", function() {
806
+ var expected = match(TestClass.spyFunction);
807
+ expect(expected.toHaveBeenCalledWith('a', 'b')).toFail();
808
+ expect(lastResult().message).toEqual("Expected spy My spy to have been called with [ 'a', 'b' ] but it was never called.");
809
+ });
810
+
811
+ it("should return a decent message when inverted", function() {
812
+ TestClass.spyFunction('a', 'b', 'c');
813
+ TestClass.spyFunction('d', 'e', 'f');
814
+ var expected = match(TestClass.spyFunction);
815
+ expect(expected.not.toHaveBeenCalledWith('a', 'b', 'c')).toFail();
816
+ expect(lastResult().message).toEqual("Expected spy My spy not to have been called with [ 'a', 'b', 'c' ] but it was.");
817
+ });
818
+
819
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('toHaveBeenCalledWith'));
820
+
821
+ describe("to build an ExpectationResult", function () {
822
+ beforeEach(function() {
823
+ var currentSuite;
824
+ var spec;
825
+ currentSuite = env.describe('default current suite', function() {
826
+ spec = env.it();
827
+ }, spec);
828
+ TestClass = { someFunction: function(a, b) {
829
+ } };
830
+ spec.spyOn(TestClass, 'someFunction');
831
+ });
832
+
833
+ it("should should handle the case of a spy", function() {
834
+ TestClass.someFunction('a', 'c');
835
+ var matcher = match(TestClass.someFunction);
836
+ matcher.toHaveBeenCalledWith('a', 'b');
837
+
838
+ var result = lastResult();
839
+ expect(result.matcherName).toEqual("toHaveBeenCalledWith");
840
+ expect(result.passed()).toFail();
841
+ expect(result.message).toContain(jasmine.pp(['a', 'b']));
842
+ expect(result.message).toContain(jasmine.pp(['a', 'c']));
843
+ expect(result.actual).toEqual(TestClass.someFunction);
844
+ expect(result.expected).toEqual(['a','b']);
845
+ });
846
+ });
847
+ });
848
+
849
+ describe("wasCalledWith", function() {
850
+ it("should alias toHaveBeenCalledWith", function() {
851
+ spyOn(TestClass, 'normalFunction');
852
+
853
+ TestClass.normalFunction(123);
854
+
855
+ expect(TestClass.normalFunction).wasCalledWith(123);
856
+ });
857
+ });
858
+
859
+ describe("wasNotCalledWith", function() {
860
+ it('should return true if the spy was NOT called with the expected args', function() {
861
+ TestClass.spyFunction('a', 'b', 'c');
862
+ expect(match(TestClass.spyFunction).wasNotCalledWith('c', 'b', 'a')).toPass();
863
+ });
864
+
865
+ it('should return false if it WAS called with the expected args', function() {
866
+ TestClass.spyFunction('a', 'b', 'c');
867
+ var expected = match(TestClass.spyFunction);
868
+ expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
869
+ var result = lastResult();
870
+ expect(result.passed()).toFail();
871
+ expect(result.expected).toEqual(['a', 'b', 'c']);
872
+ expect(result.actual.mostRecentCall.args).toEqual(['a', 'b', 'c']);
873
+ expect(result.message).toContain(jasmine.pp(result.expected));
874
+ });
875
+
876
+ it('should return true if it was not called', function() {
877
+ var expected = match(TestClass.spyFunction);
878
+ expect(expected.wasNotCalledWith('c', 'b', 'a')).toPass();
879
+ });
880
+
881
+ it('should allow matches across multiple calls', function() {
882
+ var expected = match(TestClass.spyFunction);
883
+ TestClass.spyFunction('a', 'b', 'c');
884
+ TestClass.spyFunction('d', 'e', 'f');
885
+ expect(expected.wasNotCalledWith('a', 'b', 'c')).toFail();
886
+ expect(expected.wasNotCalledWith('d', 'e', 'f')).toFail();
887
+ expect(expected.wasNotCalledWith('x', 'y', 'z')).toPass();
888
+ });
889
+
890
+ it('should throw an exception when invoked on a non-spy', shouldThrowAnExceptionWhenInvokedOnANonSpy('wasNotCalledWith'));
891
+ });
892
+ });
893
+
894
+ describe("ObjectContaining", function () {
895
+ describe("with an empty object", function () {
896
+ var containing;
897
+ beforeEach(function () {
898
+ containing = new jasmine.Matchers.ObjectContaining({});
899
+ });
900
+ it("matches everything", function () {
901
+ expect(containing.jasmineMatches("foo", [], [])).toBe(true);
902
+ });
903
+
904
+ it("says it didn't expect to contain anything", function () {
905
+ expect(containing.jasmineToString()).toEqual("<jasmine.objectContaining({ })>");
906
+ });
907
+ });
908
+
909
+ describe("with an object with items in it", function () {
910
+ var containing, mismatchKeys, mismatchValues;
911
+ beforeEach(function () {
912
+ mismatchKeys = [];
913
+ mismatchValues = [];
914
+ containing = new jasmine.Matchers.ObjectContaining({foo: "fooVal", bar: "barVal"});
915
+ });
916
+
917
+ it("doesn't match an empty object", function () {
918
+ expect(containing.jasmineMatches({}, mismatchKeys, mismatchValues)).toBe(false);
919
+ });
920
+
921
+ it("doesn't match an object with none of the specified options", function () {
922
+ expect(containing.jasmineMatches({baz:"stuff"}, mismatchKeys, mismatchValues)).toBe(false);
923
+ });
924
+
925
+ it("adds a message for each missing key", function () {
926
+ containing.jasmineMatches({foo: "fooVal"}, mismatchKeys, mismatchValues);
927
+ expect(mismatchKeys.length).toEqual(1);
928
+ });
929
+
930
+ it("doesn't match an object when the values are different", function () {
931
+ expect(containing.jasmineMatches({foo:"notFoo", bar:"notBar"}, mismatchKeys, mismatchValues)).toBe(false);
932
+ });
933
+
934
+ it("adds a message when values don't match", function () {
935
+ containing.jasmineMatches({foo: "fooVal", bar: "notBar"}, mismatchKeys, mismatchValues);
936
+ expect(mismatchValues.length).toEqual(1);
937
+ });
938
+
939
+ it("doesn't match an object with only one of the values matching", function () {
940
+ expect(containing.jasmineMatches({foo:"notFoo", bar:"barVal"}, mismatchKeys, mismatchValues)).toBe(false);
941
+ });
942
+
943
+ it("matches when all the values are the same", function () {
944
+ expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal"}, mismatchKeys, mismatchValues)).toBe(true);
945
+ });
946
+
947
+ it("matches when there are additional values", function () {
948
+ expect(containing.jasmineMatches({foo: "fooVal", bar: "barVal", baz: "bazVal"}, mismatchKeys, mismatchValues)).toBe(true);
949
+ });
950
+
951
+ it("doesn't modify missingKeys or missingValues when match is successful", function () {
952
+ containing.jasmineMatches({foo: "fooVal", bar: "barVal"}, mismatchKeys, mismatchValues);
953
+ expect(mismatchKeys.length).toEqual(0);
954
+ expect(mismatchValues.length).toEqual(0);
955
+ });
956
+
957
+ it("says what it expects to contain", function () {
958
+ expect(containing.jasmineToString()).toEqual("<jasmine.objectContaining(" + jasmine.pp({foo:"fooVal", bar:"barVal"}) + ")>");
959
+ });
960
+ });
961
+
962
+ describe("in real life", function () {
963
+ var method;
964
+ beforeEach(function () {
965
+ method = jasmine.createSpy("method");
966
+ method({a:"b", c:"d"});
967
+ });
968
+ it("works correctly for positive matches", function () {
969
+ expect(method).toHaveBeenCalledWith(jasmine.objectContaining({a:"b"}));
970
+ });
971
+
972
+ it("works correctly for negative matches", function () {
973
+ expect(method).not.toHaveBeenCalledWith(jasmine.objectContaining({z:"x"}));
974
+ });
975
+ });
976
+ });
977
+
978
+ describe("Matchers.Any", function () {
979
+ var any;
980
+ describe(".jasmineToString", function () {
981
+ describe("with Object", function () {
982
+ it("says it's looking for an object", function () {
983
+ any = jasmine.any(Object);
984
+ expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function Object.*\)>/);
985
+ });
986
+ });
987
+
988
+ describe("with Function", function () {
989
+ it("says it's looking for a function", function () {
990
+ any = jasmine.any(Function);
991
+ expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function Function.*\)>/);
992
+ });
993
+ });
994
+
995
+ describe("with String", function () {
996
+ it("says it's looking for a string", function () {
997
+ any = jasmine.any(String);
998
+ expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function String.*\)>/);
999
+ });
1000
+ });
1001
+
1002
+ describe("with Number", function () {
1003
+ it("says it's looking for a number", function () {
1004
+ any = jasmine.any(Number);
1005
+ expect(any.jasmineToString().replace(/\n/g, "")).toMatch(/<jasmine\.any\(function Number.*\)>/);
1006
+ });
1007
+ });
1008
+
1009
+ describe("with some other defined 'class'", function () {
1010
+ it("says it's looking for an object", function () {
1011
+ function MyClass () {}
1012
+ any = jasmine.any(MyClass);
1013
+ expect(any.jasmineToString().replace("\n", "")).toMatch(/<jasmine\.any\(function MyClass.*\)>/);
1014
+ });
1015
+ });
1016
+ });
1017
+
1018
+ describe(".jasmineMatches", function () {
1019
+ describe("with Object", function () {
1020
+ beforeEach(function () {
1021
+ any = jasmine.any(Object);
1022
+ });
1023
+
1024
+ it("matches an empty object", function () {
1025
+ expect(any.jasmineMatches({})).toEqual(true);
1026
+ });
1027
+
1028
+ it("matches a newed up object", function () {
1029
+ expect(any.jasmineMatches(new Object())).toEqual(true);
1030
+ });
1031
+
1032
+ it("doesn't match a string", function () {
1033
+ expect(any.jasmineMatches("")).toEqual(false);
1034
+ });
1035
+
1036
+ it("doesn't match a number", function () {
1037
+ expect(any.jasmineMatches(123)).toEqual(false);
1038
+ });
1039
+
1040
+ it("doesn't match a function", function () {
1041
+ expect(any.jasmineMatches(function () {})).toEqual(false);
1042
+ });
1043
+ });
1044
+
1045
+ describe("with Function", function () {
1046
+ beforeEach(function () {
1047
+ any = jasmine.any(Function);
1048
+ });
1049
+
1050
+ it("doesn't match an object", function () {
1051
+ expect(any.jasmineMatches({})).toEqual(false);
1052
+ });
1053
+
1054
+ it("doesn't match a string", function () {
1055
+ expect(any.jasmineMatches("")).toEqual(false);
1056
+ });
1057
+
1058
+ it("doesn't match a number", function () {
1059
+ expect(any.jasmineMatches(123)).toEqual(false);
1060
+ });
1061
+
1062
+ it("matches a function", function () {
1063
+ expect(any.jasmineMatches(function () {})).toEqual(true);
1064
+ });
1065
+ });
1066
+
1067
+ describe("with Number", function () {
1068
+ beforeEach(function () {
1069
+ any = jasmine.any(Number);
1070
+ });
1071
+
1072
+ it("doesn't match an object", function () {
1073
+ expect(any.jasmineMatches({})).toEqual(false);
1074
+ });
1075
+
1076
+ it("doesn't match a string", function () {
1077
+ expect(any.jasmineMatches("")).toEqual(false);
1078
+ });
1079
+
1080
+ it("matches a number", function () {
1081
+ expect(any.jasmineMatches(123)).toEqual(true);
1082
+ });
1083
+
1084
+ it("doesn't match a function", function () {
1085
+ expect(any.jasmineMatches(function () {})).toEqual(false);
1086
+ });
1087
+ });
1088
+
1089
+ describe("with String", function () {
1090
+ beforeEach(function () {
1091
+ any = jasmine.any(String);
1092
+ });
1093
+
1094
+ it("doesn't match an object", function () {
1095
+ expect(any.jasmineMatches({})).toEqual(false);
1096
+ });
1097
+
1098
+ it("matches a string", function () {
1099
+ expect(any.jasmineMatches("")).toEqual(true);
1100
+ });
1101
+
1102
+ it("doesn't match a number", function () {
1103
+ expect(any.jasmineMatches(123)).toEqual(false);
1104
+ });
1105
+
1106
+ it("doesn't match a function", function () {
1107
+ expect(any.jasmineMatches(function () {})).toEqual(false);
1108
+ });
1109
+ });
1110
+
1111
+ describe("with some defined 'class'", function () {
1112
+ function MyClass () {}
1113
+ beforeEach(function () {
1114
+ any = jasmine.any(MyClass);
1115
+ });
1116
+
1117
+ it("doesn't match an object", function () {
1118
+ expect(any.jasmineMatches({})).toEqual(false);
1119
+ });
1120
+
1121
+ it("doesn't match a string", function () {
1122
+ expect(any.jasmineMatches("")).toEqual(false);
1123
+ });
1124
+
1125
+ it("doesn't match a number", function () {
1126
+ expect(any.jasmineMatches(123)).toEqual(false);
1127
+ });
1128
+
1129
+ it("doesn't match a function", function () {
1130
+ expect(any.jasmineMatches(function () {})).toEqual(false);
1131
+ });
1132
+
1133
+ it("matches an instance of the defined class", function () {
1134
+ expect(any.jasmineMatches(new MyClass())).toEqual(true);
1135
+ });
1136
+ });
1137
+ });
1138
+ });
1139
+
1140
+ describe("all matchers", function() {
1141
+ it("should return null, for future-proofing, since we might eventually allow matcher chaining", function() {
1142
+ expect(match(true).toBe(true)).toBeUndefined();
1143
+ });
1144
+ });
1145
+ });