jasmine-core 2.99.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jasmine-core/boot.js +7 -6
  3. data/lib/jasmine-core/boot/boot.js +7 -6
  4. data/lib/jasmine-core/boot/node_boot.js +0 -3
  5. data/lib/jasmine-core/jasmine-html.js +228 -137
  6. data/lib/jasmine-core/jasmine.css +11 -5
  7. data/lib/jasmine-core/jasmine.js +1046 -608
  8. data/lib/jasmine-core/node_boot.js +0 -3
  9. data/lib/jasmine-core/spec/core/CallTrackerSpec.js +130 -0
  10. data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
  11. data/lib/jasmine-core/spec/core/ClockSpec.js +710 -0
  12. data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +286 -0
  13. data/lib/jasmine-core/spec/core/EnvSpec.js +200 -0
  14. data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +120 -0
  15. data/lib/jasmine-core/spec/core/ExceptionsSpec.js +46 -0
  16. data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
  17. data/lib/jasmine-core/spec/core/ExpectationSpec.js +434 -0
  18. data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
  19. data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +259 -0
  20. data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
  21. data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +332 -0
  22. data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +670 -0
  23. data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +140 -0
  24. data/lib/jasmine-core/spec/core/SpecSpec.js +407 -0
  25. data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +364 -0
  26. data/lib/jasmine-core/spec/core/SpySpec.js +177 -0
  27. data/lib/jasmine-core/spec/core/SpyStrategySpec.js +202 -0
  28. data/lib/jasmine-core/spec/core/StackTraceSpec.js +166 -0
  29. data/lib/jasmine-core/spec/core/SuiteSpec.js +123 -0
  30. data/lib/jasmine-core/spec/core/TimerSpec.js +31 -0
  31. data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +794 -0
  32. data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
  33. data/lib/jasmine-core/spec/core/UtilSpec.js +105 -0
  34. data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +91 -0
  35. data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +76 -0
  36. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +52 -0
  37. data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
  38. data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +99 -0
  39. data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +27 -0
  40. data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +13 -0
  41. data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +200 -0
  42. data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +138 -0
  43. data/lib/jasmine-core/spec/core/integration/EnvSpec.js +2344 -0
  44. data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +976 -0
  45. data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
  46. data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
  47. data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
  48. data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +645 -0
  49. data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
  50. data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +93 -0
  51. data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
  52. data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
  53. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +29 -0
  54. data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +20 -0
  55. data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +29 -0
  56. data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
  57. data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +37 -0
  58. data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
  59. data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
  60. data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
  61. data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
  62. data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
  63. data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +18 -0
  64. data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +26 -0
  65. data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +785 -0
  66. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
  67. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +47 -0
  68. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +86 -0
  69. data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +67 -0
  70. data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +43 -0
  71. data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +315 -0
  72. data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +73 -0
  73. data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +100 -0
  74. data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -0
  75. data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
  76. data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
  77. data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
  78. data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
  79. data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
  80. data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +6 -0
  81. data/lib/jasmine-core/spec/helpers/integrationMatchers.js +43 -0
  82. data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +30 -0
  83. data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +1261 -0
  84. data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
  85. data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +37 -0
  86. data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +27 -0
  87. data/lib/jasmine-core/spec/html/QueryStringSpec.js +72 -0
  88. data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
  89. data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +39 -0
  90. data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +48 -0
  91. data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +101 -0
  92. data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
  93. data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
  94. data/lib/jasmine-core/version.rb +1 -1
  95. metadata +88 -4
  96. data/lib/console/console.js +0 -190
@@ -0,0 +1,54 @@
1
+ describe("UserContext", function() {
2
+ it("Behaves just like an plain object", function() {
3
+ var context = new jasmineUnderTest.UserContext(),
4
+ properties = [];
5
+
6
+ for (var prop in context) {
7
+ if (obj.hasOwnProperty(prop)) {
8
+ properties.push(prop);
9
+ }
10
+ }
11
+
12
+ expect(properties).toEqual([]);
13
+ });
14
+
15
+ describe('.fromExisting', function() {
16
+ describe('when using an already built context as model', function() {
17
+ beforeEach(function() {
18
+ this.context = new jasmineUnderTest.UserContext();
19
+ this.context.key = 'value';
20
+ this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
21
+ });
22
+
23
+ it('returns a cloned object', function() {
24
+ expect(this.cloned).toEqual(this.context);
25
+ });
26
+
27
+ it('does not return the same object', function() {
28
+ expect(this.cloned).not.toBe(this.context);
29
+ });
30
+ });
31
+
32
+ describe('when using a regular object as parameter', function() {
33
+ beforeEach(function() {
34
+ this.context = {};
35
+ this.value = 'value'
36
+ this.context.key = this.value;
37
+ this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
38
+ });
39
+
40
+ it('returns an object with the same attributes', function() {
41
+ expect(this.cloned.key).toEqual(this.value);
42
+ });
43
+
44
+ it('does not return the same object', function() {
45
+ expect(this.cloned).not.toBe(this.context);
46
+ });
47
+
48
+ it('returns an UserContext', function() {
49
+ expect(this.cloned.constructor).toBe(jasmineUnderTest.UserContext);
50
+ });
51
+ });
52
+ });
53
+ });
54
+
@@ -0,0 +1,105 @@
1
+ describe("jasmineUnderTest.util", function() {
2
+ describe("isArray_", function() {
3
+ it("should return true if the argument is an array", function() {
4
+ expect(jasmineUnderTest.isArray_([])).toBe(true);
5
+ expect(jasmineUnderTest.isArray_(['a'])).toBe(true);
6
+ });
7
+
8
+ it("should return false if the argument is not an array", function() {
9
+ expect(jasmineUnderTest.isArray_(undefined)).toBe(false);
10
+ expect(jasmineUnderTest.isArray_({})).toBe(false);
11
+ expect(jasmineUnderTest.isArray_(function() {})).toBe(false);
12
+ expect(jasmineUnderTest.isArray_('foo')).toBe(false);
13
+ expect(jasmineUnderTest.isArray_(5)).toBe(false);
14
+ expect(jasmineUnderTest.isArray_(null)).toBe(false);
15
+ });
16
+ });
17
+
18
+ describe("isObject_", function() {
19
+ it("should return true if the argument is an object", function() {
20
+ expect(jasmineUnderTest.isObject_({})).toBe(true);
21
+ expect(jasmineUnderTest.isObject_({an: "object"})).toBe(true);
22
+ });
23
+
24
+ it("should return false if the argument is not an object", function() {
25
+ expect(jasmineUnderTest.isObject_(undefined)).toBe(false);
26
+ expect(jasmineUnderTest.isObject_([])).toBe(false);
27
+ expect(jasmineUnderTest.isObject_(function() {})).toBe(false);
28
+ expect(jasmineUnderTest.isObject_('foo')).toBe(false);
29
+ expect(jasmineUnderTest.isObject_(5)).toBe(false);
30
+ expect(jasmineUnderTest.isObject_(null)).toBe(false);
31
+ });
32
+ });
33
+
34
+ describe("isUndefined", function() {
35
+ it("reports if a variable is defined", function() {
36
+ var a;
37
+ expect(jasmineUnderTest.util.isUndefined(a)).toBe(true);
38
+ expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(true);
39
+
40
+ var undefined = "diz be undefined yo";
41
+ expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(false);
42
+ });
43
+ });
44
+
45
+ describe("getPropertyDescriptor", function() {
46
+ it("get property descriptor from object", function() {
47
+ var obj = {prop: 1},
48
+ actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
49
+ expected = Object.getOwnPropertyDescriptor(obj, 'prop');
50
+
51
+ expect(actual).toEqual(expected);
52
+ });
53
+
54
+ it("get property descriptor from object property", function() {
55
+ var proto = {prop: 1},
56
+ obj = Object.create(proto),
57
+ actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
58
+ expected = Object.getOwnPropertyDescriptor(proto, 'prop');
59
+
60
+ expect(actual).toEqual(expected);
61
+ });
62
+ });
63
+
64
+ describe("objectDifference", function() {
65
+ it("given two objects A and B, returns the properties in A not present in B", function() {
66
+ var a = {
67
+ foo: 3,
68
+ bar: 4,
69
+ baz: 5
70
+ };
71
+
72
+ var b = {
73
+ bar: 6,
74
+ quux: 7
75
+ };
76
+
77
+ expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({foo: 3, baz: 5})
78
+ });
79
+
80
+ it("only looks at own properties of both objects", function() {
81
+ function Foo() {}
82
+
83
+ Foo.prototype.x = 1;
84
+ Foo.prototype.y = 2;
85
+
86
+ var a = new Foo();
87
+ a.x = 1;
88
+
89
+ var b = new Foo();
90
+ b.y = 2;
91
+
92
+ expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({x: 1});
93
+ expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual({y: 2});
94
+ });
95
+ });
96
+
97
+ describe("jasmineFile", function() {
98
+ it("returns the file containing jasmine.util", function() {
99
+ // Chrome sometimes reports foo.js as foo.js/, so tolerate
100
+ // a trailing slash if present.
101
+ expect(jasmineUnderTest.util.jasmineFile()).toMatch(/util.js\/?$/);
102
+ expect(jasmine.util.jasmineFile()).toMatch(/jasmine.js\/?$/);
103
+ });
104
+ });
105
+ });
@@ -0,0 +1,91 @@
1
+ describe("Any", function() {
2
+ it("matches a string", function() {
3
+ var any = new jasmineUnderTest.Any(String);
4
+
5
+ expect(any.asymmetricMatch("foo")).toBe(true);
6
+ });
7
+
8
+ it("matches a number", function() {
9
+ var any = new jasmineUnderTest.Any(Number);
10
+
11
+ expect(any.asymmetricMatch(1)).toBe(true);
12
+ });
13
+
14
+ it("matches a function", function() {
15
+ var any = new jasmineUnderTest.Any(Function);
16
+
17
+ expect(any.asymmetricMatch(function(){})).toBe(true);
18
+ });
19
+
20
+ it("matches an Object", function() {
21
+ var any = new jasmineUnderTest.Any(Object);
22
+
23
+ expect(any.asymmetricMatch({})).toBe(true);
24
+ });
25
+
26
+ it("matches a Boolean", function() {
27
+ var any = new jasmineUnderTest.Any(Boolean);
28
+
29
+ expect(any.asymmetricMatch(true)).toBe(true);
30
+ });
31
+
32
+ it("matches a Map", function() {
33
+ jasmine.getEnv().requireFunctioningMaps();
34
+
35
+ var any = new jasmineUnderTest.Any(Map);
36
+
37
+ expect(any.asymmetricMatch(new Map())).toBe(true);
38
+ });
39
+
40
+ it("matches a Set", function() {
41
+ jasmine.getEnv().requireFunctioningSets();
42
+
43
+ var any = new jasmineUnderTest.Any(Set);
44
+
45
+ expect(any.asymmetricMatch(new Set())).toBe(true);
46
+ });
47
+
48
+ it("matches a TypedArray", function() {
49
+ jasmine.getEnv().requireFunctioningTypedArrays();
50
+
51
+ var any = new jasmineUnderTest.Any(Uint32Array);
52
+
53
+ expect(any.asymmetricMatch(new Uint32Array([]))).toBe(true);
54
+ });
55
+
56
+ it("matches a Symbol", function() {
57
+ jasmine.getEnv().requireFunctioningSymbols();
58
+
59
+ var any = new jasmineUnderTest.Any(Symbol);
60
+
61
+ expect(any.asymmetricMatch(Symbol())).toBe(true);
62
+ });
63
+
64
+ it("matches another constructed object", function() {
65
+ var Thing = function() {},
66
+ any = new jasmineUnderTest.Any(Thing);
67
+
68
+ expect(any.asymmetricMatch(new Thing())).toBe(true);
69
+ });
70
+
71
+ it("does not treat null as an Object", function() {
72
+ var any = new jasmineUnderTest.Any(Object);
73
+
74
+ expect(any.asymmetricMatch(null)).toBe(false);
75
+ });
76
+
77
+ it("jasmineToString's itself", function() {
78
+ var any = new jasmineUnderTest.Any(Number);
79
+
80
+ expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
81
+ expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
82
+ });
83
+
84
+ describe("when called without an argument", function() {
85
+ it("tells the user to pass a constructor or use jasmine.anything()", function() {
86
+ expect(function() {
87
+ new jasmineUnderTest.Any();
88
+ }).toThrowError(TypeError, /constructor.*anything/);
89
+ });
90
+ });
91
+ });
@@ -0,0 +1,76 @@
1
+ describe("Anything", function() {
2
+ it("matches a string", function() {
3
+ var anything = new jasmineUnderTest.Anything();
4
+
5
+ expect(anything.asymmetricMatch('foo')).toBe(true);
6
+ });
7
+
8
+ it("matches a number", function() {
9
+ var anything = new jasmineUnderTest.Anything();
10
+
11
+ expect(anything.asymmetricMatch(42)).toBe(true);
12
+ });
13
+
14
+ it("matches an object", function() {
15
+ var anything = new jasmineUnderTest.Anything();
16
+
17
+ expect(anything.asymmetricMatch({ foo: 'bar' })).toBe(true);
18
+ });
19
+
20
+ it("matches an array", function() {
21
+ var anything = new jasmineUnderTest.Anything();
22
+
23
+ expect(anything.asymmetricMatch([1,2,3])).toBe(true);
24
+ });
25
+
26
+ it("matches a Map", function() {
27
+ jasmine.getEnv().requireFunctioningMaps();
28
+
29
+ var anything = new jasmineUnderTest.Anything();
30
+
31
+ expect(anything.asymmetricMatch(new Map())).toBe(true);
32
+ });
33
+
34
+ it("matches a Set", function() {
35
+ jasmine.getEnv().requireFunctioningSets();
36
+
37
+ var anything = new jasmineUnderTest.Anything();
38
+
39
+ expect(anything.asymmetricMatch(new Set())).toBe(true);
40
+ });
41
+
42
+ it("matches a TypedArray", function() {
43
+ jasmine.getEnv().requireFunctioningTypedArrays();
44
+
45
+ var anything = new jasmineUnderTest.Anything();
46
+
47
+ expect(anything.asymmetricMatch(new Uint32Array([]))).toBe(true);
48
+ });
49
+
50
+ it("matches a Symbol", function() {
51
+ jasmine.getEnv().requireFunctioningSymbols();
52
+
53
+ var anything = new jasmineUnderTest.Anything();
54
+
55
+ expect(anything.asymmetricMatch(Symbol())).toBe(true);
56
+ });
57
+
58
+ it("doesn't match undefined", function() {
59
+ var anything = new jasmineUnderTest.Anything();
60
+
61
+ expect(anything.asymmetricMatch()).toBe(false);
62
+ expect(anything.asymmetricMatch(undefined)).toBe(false);
63
+ });
64
+
65
+ it("doesn't match null", function() {
66
+ var anything = new jasmineUnderTest.Anything();
67
+
68
+ expect(anything.asymmetricMatch(null)).toBe(false);
69
+ });
70
+
71
+ it("jasmineToString's itself", function() {
72
+ var anything = new jasmineUnderTest.Anything();
73
+
74
+ expect(anything.jasmineToString()).toEqual("<jasmine.anything>");
75
+ });
76
+ });
@@ -0,0 +1,52 @@
1
+ describe("ArrayContaining", function() {
2
+ it("matches any actual to an empty array", function() {
3
+ var containing = new jasmineUnderTest.ArrayContaining([]);
4
+
5
+ expect(containing.asymmetricMatch("foo")).toBe(true);
6
+ });
7
+
8
+ it("does not work when not passed an array", function() {
9
+ var containing = new jasmineUnderTest.ArrayContaining("foo");
10
+
11
+ expect(function() {
12
+ containing.asymmetricMatch([]);
13
+ }).toThrowError(/not 'foo'/);
14
+ });
15
+
16
+ it("matches when the item is in the actual", function() {
17
+ var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
18
+
19
+ expect(containing.asymmetricMatch(["foo"])).toBe(true);
20
+ });
21
+
22
+ it("matches when additional items are in the actual", function() {
23
+ var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
24
+
25
+ expect(containing.asymmetricMatch(["foo", "bar"])).toBe(true);
26
+ });
27
+
28
+ it("does not match when the item is not in the actual", function() {
29
+ var containing = new jasmineUnderTest.ArrayContaining(["foo"]);
30
+
31
+ expect(containing.asymmetricMatch(["bar"])).toBe(false);
32
+ });
33
+
34
+ it("jasmineToStrings itself", function() {
35
+ var containing = new jasmineUnderTest.ArrayContaining([]);
36
+
37
+ expect(containing.jasmineToString()).toMatch("<jasmine.arrayContaining");
38
+ });
39
+
40
+ it("uses custom equality testers", function() {
41
+ var tester = function(a, b) {
42
+ // All "foo*" strings match each other.
43
+ if (typeof a == "string" && typeof b == "string" &&
44
+ a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
45
+ return true;
46
+ }
47
+ };
48
+ var containing = new jasmineUnderTest.ArrayContaining(["fooVal"]);
49
+
50
+ expect(containing.asymmetricMatch(["fooBar"], [tester])).toBe(true);
51
+ });
52
+ });
@@ -0,0 +1,47 @@
1
+ describe("ArrayWithExactContents", function() {
2
+ it("matches an array with the same items in a different order", function() {
3
+ var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
4
+
5
+ expect(matcher.asymmetricMatch([2, 'a', /a/])).toBe(true);
6
+ });
7
+
8
+ it("does not work when not passed an array", function() {
9
+ var matcher = new jasmineUnderTest.ArrayWithExactContents("foo");
10
+
11
+ expect(function() {
12
+ matcher.asymmetricMatch([]);
13
+ }).toThrowError(/not 'foo'/);
14
+ });
15
+
16
+ it("does not match when an item is missing", function() {
17
+ var matcher = new jasmineUnderTest.ArrayWithExactContents(['a', 2, /a/]);
18
+
19
+ expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
20
+ expect(matcher.asymmetricMatch(['a', 2, undefined])).toBe(false);
21
+ });
22
+
23
+ it("does not match when there is an extra item", function() {
24
+ var matcher = new jasmineUnderTest.ArrayWithExactContents(['a']);
25
+
26
+ expect(matcher.asymmetricMatch(['a', 2])).toBe(false);
27
+ });
28
+
29
+ it("jasmineToStrings itself", function() {
30
+ var matcher = new jasmineUnderTest.ArrayWithExactContents([]);
31
+
32
+ expect(matcher.jasmineToString()).toMatch("<jasmine.arrayWithExactContents");
33
+ });
34
+
35
+ it("uses custom equality testers", function() {
36
+ var tester = function(a, b) {
37
+ // All "foo*" strings match each other.
38
+ if (typeof a == "string" && typeof b == "string" &&
39
+ a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
40
+ return true;
41
+ }
42
+ };
43
+ var matcher = new jasmineUnderTest.ArrayWithExactContents(["fooVal"]);
44
+
45
+ expect(matcher.asymmetricMatch(["fooBar"], [tester])).toBe(true);
46
+ });
47
+ });
@@ -0,0 +1,99 @@
1
+ describe("ObjectContaining", function() {
2
+
3
+ it("matches any actual to an empty object", function() {
4
+ var containing = new jasmineUnderTest.ObjectContaining({});
5
+
6
+ expect(containing.asymmetricMatch("foo")).toBe(true);
7
+ });
8
+
9
+ it("does not match an empty object actual", function() {
10
+ var containing = new jasmineUnderTest.ObjectContaining("foo");
11
+
12
+ expect(function() {
13
+ containing.asymmetricMatch({})
14
+ }).toThrowError(/not 'foo'/)
15
+ });
16
+
17
+ it("matches when the key/value pair is present in the actual", function() {
18
+ var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
19
+
20
+ expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(true);
21
+ });
22
+
23
+ it("does not match when the key/value pair is not present in the actual", function() {
24
+ var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
25
+
26
+ expect(containing.asymmetricMatch({bar: "barVal", quux: "quuxVal"})).toBe(false);
27
+ });
28
+
29
+ it("does not match when the key is present but the value is different in the actual", function() {
30
+ var containing = new jasmineUnderTest.ObjectContaining({foo: "other"});
31
+
32
+ expect(containing.asymmetricMatch({foo: "fooVal", bar: "barVal"})).toBe(false);
33
+ });
34
+
35
+ it("jasmineToString's itself", function() {
36
+ var containing = new jasmineUnderTest.ObjectContaining({});
37
+
38
+ expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
39
+ });
40
+
41
+ it("matches recursively", function() {
42
+ var containing = new jasmineUnderTest.ObjectContaining({one: new jasmineUnderTest.ObjectContaining({two: {}})});
43
+
44
+ expect(containing.asymmetricMatch({one: {two: {}}})).toBe(true);
45
+ });
46
+
47
+ it("matches when key is present with undefined value", function() {
48
+ var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
49
+
50
+ expect(containing.asymmetricMatch({ one: undefined })).toBe(true);
51
+ });
52
+
53
+ it("does not match when key with undefined value is not present", function() {
54
+ var containing = new jasmineUnderTest.ObjectContaining({ one: undefined });
55
+
56
+ expect(containing.asymmetricMatch({})).toBe(false);
57
+ });
58
+
59
+ it("matches defined properties", function(){
60
+ var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
61
+
62
+ var definedPropertyObject = {};
63
+ Object.defineProperty(definedPropertyObject, "foo", {
64
+ get: function() { return "fooVal" }
65
+ });
66
+ expect(containing.asymmetricMatch(definedPropertyObject)).toBe(true);
67
+ });
68
+
69
+ it("matches prototype properties", function(){
70
+ var containing = new jasmineUnderTest.ObjectContaining({ foo: "fooVal" });
71
+
72
+ var prototypeObject = {foo: "fooVal"};
73
+ var obj;
74
+
75
+ if (Object.create) {
76
+ obj = Object.create(prototypeObject);
77
+ } else {
78
+ function Foo() {}
79
+ Foo.prototype = prototypeObject;
80
+ Foo.prototype.constructor = Foo;
81
+ obj = new Foo();
82
+ }
83
+
84
+ expect(containing.asymmetricMatch(obj)).toBe(true);
85
+ });
86
+
87
+ it("uses custom equality testers", function() {
88
+ var tester = function(a, b) {
89
+ // All "foo*" strings match each other.
90
+ if (typeof a == "string" && typeof b == "string" &&
91
+ a.substr(0, 3) == "foo" && b.substr(0, 3) == "foo") {
92
+ return true;
93
+ }
94
+ };
95
+ var containing = new jasmineUnderTest.ObjectContaining({foo: "fooVal"});
96
+
97
+ expect(containing.asymmetricMatch({foo: "fooBar"}, [tester])).toBe(true);
98
+ });
99
+ });