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.
- checksums.yaml +4 -4
- data/lib/jasmine-core/boot.js +7 -6
- data/lib/jasmine-core/boot/boot.js +7 -6
- data/lib/jasmine-core/boot/node_boot.js +0 -3
- data/lib/jasmine-core/jasmine-html.js +228 -137
- data/lib/jasmine-core/jasmine.css +11 -5
- data/lib/jasmine-core/jasmine.js +1046 -608
- data/lib/jasmine-core/node_boot.js +0 -3
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +130 -0
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +710 -0
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +286 -0
- data/lib/jasmine-core/spec/core/EnvSpec.js +200 -0
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +120 -0
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +46 -0
- data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +434 -0
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
- data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +259 -0
- data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +332 -0
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +670 -0
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +140 -0
- data/lib/jasmine-core/spec/core/SpecSpec.js +407 -0
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +364 -0
- data/lib/jasmine-core/spec/core/SpySpec.js +177 -0
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +202 -0
- data/lib/jasmine-core/spec/core/StackTraceSpec.js +166 -0
- data/lib/jasmine-core/spec/core/SuiteSpec.js +123 -0
- data/lib/jasmine-core/spec/core/TimerSpec.js +31 -0
- data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +794 -0
- data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +105 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +91 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +76 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +52 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +99 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +27 -0
- data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +13 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +200 -0
- data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +138 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +2344 -0
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +976 -0
- data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
- data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +645 -0
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +93 -0
- data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
- data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +29 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +29 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +37 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
- data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +18 -0
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +26 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +785 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +86 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +67 -0
- data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +315 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +73 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +100 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -0
- data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
- data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
- data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
- data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
- data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
- data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +6 -0
- data/lib/jasmine-core/spec/helpers/integrationMatchers.js +43 -0
- data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +30 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +1261 -0
- data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
- data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +37 -0
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +27 -0
- data/lib/jasmine-core/spec/html/QueryStringSpec.js +72 -0
- data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +39 -0
- data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +48 -0
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +101 -0
- data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
- data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
- data/lib/jasmine-core/version.rb +1 -1
- metadata +88 -4
- data/lib/console/console.js +0 -190
@@ -0,0 +1,47 @@
|
|
1
|
+
describe("DiffBuilder", function() {
|
2
|
+
it("records the actual and expected objects", function() {
|
3
|
+
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
4
|
+
diffBuilder.record({x: 'actual'}, {x: 'expected'});
|
5
|
+
|
6
|
+
expect(diffBuilder.getMessage()).toEqual("Expected Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
|
7
|
+
});
|
8
|
+
|
9
|
+
it("prints the path at which the difference was found", function() {
|
10
|
+
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
11
|
+
|
12
|
+
diffBuilder.withPath('foo', function() {
|
13
|
+
diffBuilder.record({x: 'actual'}, {x: 'expected'});
|
14
|
+
});
|
15
|
+
|
16
|
+
expect(diffBuilder.getMessage()).toEqual("Expected $.foo = Object({ x: 'actual' }) to equal Object({ x: 'expected' }).");
|
17
|
+
});
|
18
|
+
|
19
|
+
it("prints multiple messages, separated by newlines", function() {
|
20
|
+
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
21
|
+
|
22
|
+
diffBuilder.withPath('foo', function() {
|
23
|
+
diffBuilder.record(1, 2);
|
24
|
+
});
|
25
|
+
|
26
|
+
var message =
|
27
|
+
"Expected $.foo = 1 to equal 2.\n" +
|
28
|
+
"Expected 3 to equal 4.";
|
29
|
+
|
30
|
+
diffBuilder.record(3, 4);
|
31
|
+
expect(diffBuilder.getMessage()).toEqual(message);
|
32
|
+
});
|
33
|
+
|
34
|
+
it("allows customization of the message", function() {
|
35
|
+
var diffBuilder = jasmineUnderTest.DiffBuilder();
|
36
|
+
|
37
|
+
function darthVaderFormatter(actual, expected, path) {
|
38
|
+
return "I find your lack of " + expected + " disturbing. (was " + actual + ", at " + path + ")"
|
39
|
+
}
|
40
|
+
|
41
|
+
diffBuilder.withPath('x', function() {
|
42
|
+
diffBuilder.record('bar', 'foo', darthVaderFormatter);
|
43
|
+
});
|
44
|
+
|
45
|
+
expect(diffBuilder.getMessage()).toEqual("I find your lack of foo disturbing. (was bar, at $.x)");
|
46
|
+
});
|
47
|
+
});
|
@@ -0,0 +1,13 @@
|
|
1
|
+
describe('NullDiffBuilder', function() {
|
2
|
+
it('responds to withPath() by calling the passed function', function() {
|
3
|
+
var spy = jasmine.createSpy('callback');
|
4
|
+
jasmineUnderTest.NullDiffBuilder().withPath('does not matter', spy);
|
5
|
+
expect(spy).toHaveBeenCalled();
|
6
|
+
});
|
7
|
+
|
8
|
+
it('responds to record()', function() {
|
9
|
+
expect(function() {
|
10
|
+
jasmineUnderTest.NullDiffBuilder().record('does not matter');
|
11
|
+
}).not.toThrow();
|
12
|
+
})
|
13
|
+
});
|
@@ -0,0 +1,43 @@
|
|
1
|
+
describe('ObjectPath', function() {
|
2
|
+
var ObjectPath = jasmineUnderTest.ObjectPath;
|
3
|
+
|
4
|
+
it('represents the path to a node in an object tree', function() {
|
5
|
+
expect(new ObjectPath(['foo', 'bar']).toString()).toEqual('$.foo.bar');
|
6
|
+
});
|
7
|
+
|
8
|
+
it('has a depth', function() {
|
9
|
+
expect(new ObjectPath().depth()).toEqual(0);
|
10
|
+
expect(new ObjectPath(['foo']).depth()).toEqual(1);
|
11
|
+
});
|
12
|
+
|
13
|
+
it('renders numbers as array access', function() {
|
14
|
+
expect(new ObjectPath(['foo', 0]).toString()).toEqual('$.foo[0]');
|
15
|
+
});
|
16
|
+
|
17
|
+
it('renders properties that are valid identifiers with dot notation', function() {
|
18
|
+
expect(new ObjectPath(['foo123']).toString()).toEqual('$.foo123');
|
19
|
+
expect(new ObjectPath(['x_y']).toString()).toEqual('$.x_y');
|
20
|
+
expect(new ObjectPath(['A$B']).toString()).toEqual('$.A$B');
|
21
|
+
});
|
22
|
+
|
23
|
+
it('renders properties with non-identifier-safe characters with square bracket notation', function() {
|
24
|
+
expect(new ObjectPath(['a b c']).toString()).toEqual("$['a b c']");
|
25
|
+
expect(new ObjectPath(['1hello']).toString()).toEqual("$['1hello']");
|
26
|
+
});
|
27
|
+
|
28
|
+
it('renders as the empty string when empty', function() {
|
29
|
+
expect(new ObjectPath().toString()).toEqual('');
|
30
|
+
});
|
31
|
+
|
32
|
+
it('stringifies properties that are not strings or numbers', function() {
|
33
|
+
expect(new ObjectPath([{}]).toString()).toEqual("$['[object Object]']");
|
34
|
+
});
|
35
|
+
|
36
|
+
it('can be created based on another path', function() {
|
37
|
+
var root = new ObjectPath();
|
38
|
+
var path = root.add('foo');
|
39
|
+
|
40
|
+
expect(path.toString()).toEqual('$.foo');
|
41
|
+
expect(root.toString()).toEqual('');
|
42
|
+
})
|
43
|
+
});
|
@@ -0,0 +1,645 @@
|
|
1
|
+
describe("matchersUtil", function() {
|
2
|
+
describe("equals", function() {
|
3
|
+
it("passes for literals that are triple-equal", function() {
|
4
|
+
expect(jasmineUnderTest.matchersUtil.equals(null, null)).toBe(true);
|
5
|
+
expect(jasmineUnderTest.matchersUtil.equals(void 0, void 0)).toBe(true);
|
6
|
+
});
|
7
|
+
|
8
|
+
it("fails for things that are not equivalent", function() {
|
9
|
+
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, 1)).toBe(false);
|
10
|
+
});
|
11
|
+
|
12
|
+
it("passes for Strings that are equivalent", function() {
|
13
|
+
expect(jasmineUnderTest.matchersUtil.equals("foo", "foo")).toBe(true);
|
14
|
+
});
|
15
|
+
|
16
|
+
it("fails for Strings that are not equivalent", function() {
|
17
|
+
expect(jasmineUnderTest.matchersUtil.equals("foo", "bar")).toBe(false);
|
18
|
+
});
|
19
|
+
|
20
|
+
it("passes for Numbers that are equivalent", function() {
|
21
|
+
expect(jasmineUnderTest.matchersUtil.equals(123, 123)).toBe(true);
|
22
|
+
});
|
23
|
+
|
24
|
+
it("fails for Numbers that are not equivalent", function() {
|
25
|
+
expect(jasmineUnderTest.matchersUtil.equals(123, 456)).toBe(false);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("passes for Dates that are equivalent", function() {
|
29
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Jan 1, 1970"))).toBe(true);
|
30
|
+
});
|
31
|
+
|
32
|
+
it("fails for Dates that are not equivalent", function() {
|
33
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Date("Jan 1, 1970"), new Date("Feb 3, 1991"))).toBe(false);
|
34
|
+
});
|
35
|
+
|
36
|
+
it("passes for Booleans that are equivalent", function() {
|
37
|
+
expect(jasmineUnderTest.matchersUtil.equals(true, true)).toBe(true);
|
38
|
+
});
|
39
|
+
|
40
|
+
it("fails for Booleans that are not equivalent", function() {
|
41
|
+
expect(jasmineUnderTest.matchersUtil.equals(true, false)).toBe(false);
|
42
|
+
});
|
43
|
+
|
44
|
+
it("passes for RegExps that are equivalent", function() {
|
45
|
+
expect(jasmineUnderTest.matchersUtil.equals(/foo/, /foo/)).toBe(true);
|
46
|
+
});
|
47
|
+
|
48
|
+
it("fails for RegExps that are not equivalent", function() {
|
49
|
+
expect(jasmineUnderTest.matchersUtil.equals(/foo/, /bar/)).toBe(false);
|
50
|
+
expect(jasmineUnderTest.matchersUtil.equals(new RegExp("foo", "i"), new RegExp("foo"))).toBe(false);
|
51
|
+
});
|
52
|
+
|
53
|
+
it("passes for Arrays that are equivalent", function() {
|
54
|
+
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2])).toBe(true);
|
55
|
+
});
|
56
|
+
|
57
|
+
it("passes for Arrays that are equivalent, with elements added by changing length", function() {
|
58
|
+
var foo = [];
|
59
|
+
foo.length = 1;
|
60
|
+
|
61
|
+
expect(jasmineUnderTest.matchersUtil.equals(foo, [undefined])).toBe(true);
|
62
|
+
});
|
63
|
+
|
64
|
+
it("fails for Arrays that have different lengths", function() {
|
65
|
+
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
|
66
|
+
});
|
67
|
+
|
68
|
+
it("fails for Arrays that have different elements", function() {
|
69
|
+
expect(jasmineUnderTest.matchersUtil.equals([1, 2, 3], [1, 5, 3])).toBe(false);
|
70
|
+
});
|
71
|
+
|
72
|
+
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
73
|
+
var one = [1,2,3],
|
74
|
+
two = [1,2,3];
|
75
|
+
|
76
|
+
one.foo = 'bar';
|
77
|
+
two.foo = 'baz';
|
78
|
+
|
79
|
+
expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(false);
|
80
|
+
});
|
81
|
+
|
82
|
+
it("passes for Arrays with equivalent contents and properties", function() {
|
83
|
+
var one = [1,2,3],
|
84
|
+
two = [1,2,3];
|
85
|
+
|
86
|
+
one.foo = 'bar';
|
87
|
+
two.foo = 'bar';
|
88
|
+
|
89
|
+
expect(jasmineUnderTest.matchersUtil.equals(one, two)).toBe(true);
|
90
|
+
});
|
91
|
+
|
92
|
+
it("passes for Errors that are the same type and have the same message", function() {
|
93
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("foo"))).toBe(true);
|
94
|
+
});
|
95
|
+
|
96
|
+
it("fails for Errors that are the same type and have different messages", function() {
|
97
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Error("foo"), new Error("bar"))).toBe(false);
|
98
|
+
});
|
99
|
+
|
100
|
+
it("fails for objects with different constructors", function() {
|
101
|
+
function One() {}
|
102
|
+
function Two() {}
|
103
|
+
|
104
|
+
expect(jasmineUnderTest.matchersUtil.equals(new One(), new Two())).toBe(false);
|
105
|
+
});
|
106
|
+
|
107
|
+
it("passes for Objects that are equivalent (simple case)", function() {
|
108
|
+
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, {a: "foo"})).toBe(true);
|
109
|
+
});
|
110
|
+
|
111
|
+
it("fails for Objects that are not equivalent (simple case)", function() {
|
112
|
+
expect(jasmineUnderTest.matchersUtil.equals({a: "foo"}, {a: "bar"})).toBe(false);
|
113
|
+
});
|
114
|
+
|
115
|
+
it("passes for Objects that are equivalent (deep case)", function() {
|
116
|
+
expect(jasmineUnderTest.matchersUtil.equals({a: "foo", b: { c: "bar"}}, {a: "foo", b: { c: "bar"}})).toBe(true);
|
117
|
+
});
|
118
|
+
|
119
|
+
it("fails for Objects that are not equivalent (deep case)", function() {
|
120
|
+
expect(jasmineUnderTest.matchersUtil.equals({a: "foo", b: { c: "baz"}}, {a: "foo", b: { c: "bar"}})).toBe(false);
|
121
|
+
});
|
122
|
+
|
123
|
+
it("passes for Objects that are equivalent (with cycles)", function() {
|
124
|
+
var actual = { a: "foo" },
|
125
|
+
expected = { a: "foo" };
|
126
|
+
|
127
|
+
actual.b = actual;
|
128
|
+
expected.b = actual;
|
129
|
+
|
130
|
+
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(true);
|
131
|
+
});
|
132
|
+
|
133
|
+
it("fails for Objects that are not equivalent (with cycles)", function() {
|
134
|
+
var actual = { a: "foo" },
|
135
|
+
expected = { a: "bar" };
|
136
|
+
|
137
|
+
actual.b = actual;
|
138
|
+
expected.b = actual;
|
139
|
+
|
140
|
+
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
|
141
|
+
});
|
142
|
+
|
143
|
+
it("fails for Objects that have the same number of keys, but different keys/values", function () {
|
144
|
+
var expected = { a: undefined },
|
145
|
+
actual = { b: 1 };
|
146
|
+
|
147
|
+
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
|
148
|
+
})
|
149
|
+
|
150
|
+
it("fails when comparing an empty object to an empty array (issue #114)", function() {
|
151
|
+
var emptyObject = {},
|
152
|
+
emptyArray = [];
|
153
|
+
|
154
|
+
expect(jasmineUnderTest.matchersUtil.equals(emptyObject, emptyArray)).toBe(false);
|
155
|
+
expect(jasmineUnderTest.matchersUtil.equals(emptyArray, emptyObject)).toBe(false);
|
156
|
+
});
|
157
|
+
|
158
|
+
it("passes for equivalent frozen objects (GitHub issue #266)", function() {
|
159
|
+
var a = { foo: 1 },
|
160
|
+
b = {foo: 1 };
|
161
|
+
|
162
|
+
Object.freeze(a);
|
163
|
+
Object.freeze(b);
|
164
|
+
|
165
|
+
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
166
|
+
});
|
167
|
+
|
168
|
+
it("passes for equivalent Promises (GitHub issue #1314)", function() {
|
169
|
+
if (typeof Promise === 'undefined') { return; }
|
170
|
+
|
171
|
+
var p1 = new Promise(function () {}),
|
172
|
+
p2 = new Promise(function () {});
|
173
|
+
|
174
|
+
expect(jasmineUnderTest.matchersUtil.equals(p1, p1)).toBe(true);
|
175
|
+
expect(jasmineUnderTest.matchersUtil.equals(p1, p2)).toBe(false);
|
176
|
+
});
|
177
|
+
|
178
|
+
describe("when running in a browser", function() {
|
179
|
+
function isNotRunningInBrowser() {
|
180
|
+
return typeof document === 'undefined'
|
181
|
+
}
|
182
|
+
|
183
|
+
it("passes for equivalent DOM nodes", function() {
|
184
|
+
if (isNotRunningInBrowser()) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
var a = document.createElement("div");
|
188
|
+
a.setAttribute("test-attr", "attr-value");
|
189
|
+
a.appendChild(document.createTextNode('test'));
|
190
|
+
|
191
|
+
var b = document.createElement("div");
|
192
|
+
b.setAttribute("test-attr", "attr-value");
|
193
|
+
b.appendChild(document.createTextNode('test'));
|
194
|
+
|
195
|
+
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
196
|
+
});
|
197
|
+
|
198
|
+
it("passes for equivalent objects from different frames", function() {
|
199
|
+
if (isNotRunningInBrowser()) {
|
200
|
+
return;
|
201
|
+
}
|
202
|
+
var iframe = document.createElement('iframe');
|
203
|
+
document.body.appendChild(iframe);
|
204
|
+
iframe.contentWindow.eval('window.testObject = {}');
|
205
|
+
expect(jasmineUnderTest.matchersUtil.equals({}, iframe.contentWindow.testObject)).toBe(true);
|
206
|
+
document.body.removeChild(iframe);
|
207
|
+
});
|
208
|
+
|
209
|
+
it("fails for DOM nodes with different attributes or child nodes", function() {
|
210
|
+
if (isNotRunningInBrowser()) {
|
211
|
+
return;
|
212
|
+
}
|
213
|
+
var a = document.createElement("div");
|
214
|
+
a.setAttribute("test-attr", "attr-value")
|
215
|
+
a.appendChild(document.createTextNode('test'));
|
216
|
+
|
217
|
+
var b = document.createElement("div");
|
218
|
+
b.setAttribute("test-attr", "attr-value2")
|
219
|
+
b.appendChild(document.createTextNode('test'));
|
220
|
+
|
221
|
+
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(false);
|
222
|
+
|
223
|
+
b.setAttribute("test-attr", "attr-value");
|
224
|
+
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
225
|
+
|
226
|
+
b.appendChild(document.createTextNode('2'));
|
227
|
+
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(false);
|
228
|
+
|
229
|
+
a.appendChild(document.createTextNode('2'));
|
230
|
+
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
231
|
+
});
|
232
|
+
});
|
233
|
+
|
234
|
+
describe("when running in Node", function() {
|
235
|
+
function isNotRunningInNode() {
|
236
|
+
return typeof require !== 'function'
|
237
|
+
}
|
238
|
+
|
239
|
+
it("passes for equivalent objects from different vm contexts", function() {
|
240
|
+
if (isNotRunningInNode()) {
|
241
|
+
return;
|
242
|
+
}
|
243
|
+
var vm = require('vm');
|
244
|
+
var sandbox = {
|
245
|
+
obj: null
|
246
|
+
};
|
247
|
+
vm.runInNewContext('obj = {a: 1, b: 2}', sandbox);
|
248
|
+
|
249
|
+
expect(jasmineUnderTest.matchersUtil.equals(sandbox.obj, {a: 1, b: 2})).toBe(true);
|
250
|
+
});
|
251
|
+
|
252
|
+
it("passes for equivalent arrays from different vm contexts", function() {
|
253
|
+
if (isNotRunningInNode()) {
|
254
|
+
return;
|
255
|
+
}
|
256
|
+
var vm = require('vm');
|
257
|
+
var sandbox = {
|
258
|
+
arr: null
|
259
|
+
};
|
260
|
+
vm.runInNewContext('arr = [1, 2]', sandbox);
|
261
|
+
|
262
|
+
expect(jasmineUnderTest.matchersUtil.equals(sandbox.arr, [1, 2])).toBe(true);
|
263
|
+
});
|
264
|
+
});
|
265
|
+
|
266
|
+
it("passes when Any is used", function() {
|
267
|
+
var number = 3,
|
268
|
+
anyNumber = new jasmineUnderTest.Any(Number);
|
269
|
+
|
270
|
+
expect(jasmineUnderTest.matchersUtil.equals(number, anyNumber)).toBe(true);
|
271
|
+
expect(jasmineUnderTest.matchersUtil.equals(anyNumber, number)).toBe(true);
|
272
|
+
});
|
273
|
+
|
274
|
+
it("fails when Any is compared to something unexpected", function() {
|
275
|
+
var number = 3,
|
276
|
+
anyString = new jasmineUnderTest.Any(String);
|
277
|
+
|
278
|
+
expect(jasmineUnderTest.matchersUtil.equals(number, anyString)).toBe(false);
|
279
|
+
expect(jasmineUnderTest.matchersUtil.equals(anyString, number)).toBe(false);
|
280
|
+
});
|
281
|
+
|
282
|
+
it("passes when ObjectContaining is used", function() {
|
283
|
+
var obj = {
|
284
|
+
foo: 3,
|
285
|
+
bar: 7
|
286
|
+
},
|
287
|
+
containing = new jasmineUnderTest.ObjectContaining({foo: 3});
|
288
|
+
|
289
|
+
expect(jasmineUnderTest.matchersUtil.equals(obj, containing)).toBe(true);
|
290
|
+
expect(jasmineUnderTest.matchersUtil.equals(containing, obj)).toBe(true);
|
291
|
+
});
|
292
|
+
|
293
|
+
it("passes when an asymmetric equality tester returns true", function() {
|
294
|
+
var tester = { asymmetricMatch: function(other) { return true; } };
|
295
|
+
|
296
|
+
expect(jasmineUnderTest.matchersUtil.equals(false, tester)).toBe(true);
|
297
|
+
expect(jasmineUnderTest.matchersUtil.equals(tester, false)).toBe(true);
|
298
|
+
});
|
299
|
+
|
300
|
+
it("fails when an asymmetric equality tester returns false", function() {
|
301
|
+
var tester = { asymmetricMatch: function(other) { return false; } };
|
302
|
+
|
303
|
+
expect(jasmineUnderTest.matchersUtil.equals(true, tester)).toBe(false);
|
304
|
+
expect(jasmineUnderTest.matchersUtil.equals(tester, true)).toBe(false);
|
305
|
+
});
|
306
|
+
|
307
|
+
it("passes when ArrayContaining is used", function() {
|
308
|
+
var arr = ["foo", "bar"];
|
309
|
+
|
310
|
+
expect(jasmineUnderTest.matchersUtil.equals(arr, new jasmineUnderTest.ArrayContaining(["bar"]))).toBe(true);
|
311
|
+
});
|
312
|
+
|
313
|
+
it("passes when a custom equality matcher returns true", function() {
|
314
|
+
var tester = function(a, b) { return true; };
|
315
|
+
|
316
|
+
expect(jasmineUnderTest.matchersUtil.equals(1, 2, [tester])).toBe(true);
|
317
|
+
});
|
318
|
+
|
319
|
+
it("passes for two empty Objects", function () {
|
320
|
+
expect(jasmineUnderTest.matchersUtil.equals({}, {})).toBe(true);
|
321
|
+
});
|
322
|
+
|
323
|
+
describe("when a custom equality matcher is installed that returns 'undefined'", function () {
|
324
|
+
var tester = function(a, b) { return jasmine.undefined; };
|
325
|
+
|
326
|
+
it("passes for two empty Objects", function () {
|
327
|
+
expect(jasmineUnderTest.matchersUtil.equals({}, {}, [tester])).toBe(true);
|
328
|
+
});
|
329
|
+
});
|
330
|
+
|
331
|
+
it("fails for equivalents when a custom equality matcher returns false", function() {
|
332
|
+
var tester = function(a, b) { return false; };
|
333
|
+
|
334
|
+
expect(jasmineUnderTest.matchersUtil.equals(1, 1, [tester])).toBe(false);
|
335
|
+
});
|
336
|
+
|
337
|
+
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
338
|
+
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
339
|
+
symmetricTester = function(a, b) { return false; };
|
340
|
+
|
341
|
+
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
342
|
+
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
343
|
+
});
|
344
|
+
|
345
|
+
it("passes custom equality matchers to asymmetric equality testers", function() {
|
346
|
+
var tester = function(a, b) {};
|
347
|
+
var asymmetricTester = { asymmetricMatch: jasmine.createSpy('asymmetricMatch') };
|
348
|
+
asymmetricTester.asymmetricMatch.and.returnValue(true);
|
349
|
+
var other = {};
|
350
|
+
|
351
|
+
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, other, [tester])).toBe(true);
|
352
|
+
expect(asymmetricTester.asymmetricMatch).toHaveBeenCalledWith(other, [tester]);
|
353
|
+
});
|
354
|
+
|
355
|
+
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
356
|
+
var any1 = new jasmineUnderTest.Any(Function),
|
357
|
+
any2 = new jasmineUnderTest.Any(Function);
|
358
|
+
|
359
|
+
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
360
|
+
});
|
361
|
+
|
362
|
+
it("passes for null prototype objects with same properties", function () {
|
363
|
+
var objA = Object.create(null),
|
364
|
+
objB = Object.create(null);
|
365
|
+
|
366
|
+
objA.name = 'test';
|
367
|
+
objB.name = 'test';
|
368
|
+
|
369
|
+
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(true);
|
370
|
+
});
|
371
|
+
|
372
|
+
it("fails for null prototype objects with different properties", function () {
|
373
|
+
var objA = Object.create(null),
|
374
|
+
objB = Object.create(null);
|
375
|
+
|
376
|
+
objA.name = 'test';
|
377
|
+
objB.test = 'name';
|
378
|
+
|
379
|
+
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(false);
|
380
|
+
});
|
381
|
+
|
382
|
+
it("passes when comparing two empty sets", function() {
|
383
|
+
jasmine.getEnv().requireFunctioningSets();
|
384
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Set(), new Set())).toBe(true);
|
385
|
+
});
|
386
|
+
|
387
|
+
it("passes when comparing identical sets", function() {
|
388
|
+
jasmine.getEnv().requireFunctioningSets();
|
389
|
+
|
390
|
+
var setA = new Set();
|
391
|
+
setA.add(6);
|
392
|
+
setA.add(5);
|
393
|
+
var setB = new Set();
|
394
|
+
setB.add(6);
|
395
|
+
setB.add(5);
|
396
|
+
|
397
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
398
|
+
});
|
399
|
+
|
400
|
+
it("passes when comparing identical sets with different insertion order and simple elements", function() {
|
401
|
+
jasmine.getEnv().requireFunctioningSets();
|
402
|
+
|
403
|
+
var setA = new Set();
|
404
|
+
setA.add(3);
|
405
|
+
setA.add(6);
|
406
|
+
var setB = new Set();
|
407
|
+
setB.add(6);
|
408
|
+
setB.add(3);
|
409
|
+
|
410
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
411
|
+
});
|
412
|
+
|
413
|
+
it("passes when comparing identical sets with different insertion order and complex elements 1", function() {
|
414
|
+
jasmine.getEnv().requireFunctioningSets();
|
415
|
+
|
416
|
+
var setA1 = new Set();
|
417
|
+
setA1.add(['a',3]);
|
418
|
+
setA1.add([6,1]);
|
419
|
+
var setA2 = new Set();
|
420
|
+
setA1.add(['y',3]);
|
421
|
+
setA1.add([6,1]);
|
422
|
+
var setA = new Set();
|
423
|
+
setA.add(setA1);
|
424
|
+
setA.add(setA2);
|
425
|
+
|
426
|
+
|
427
|
+
var setB1 = new Set();
|
428
|
+
setB1.add([6,1]);
|
429
|
+
setB1.add(['a',3]);
|
430
|
+
var setB2 = new Set();
|
431
|
+
setB1.add([6,1]);
|
432
|
+
setB1.add(['y',3]);
|
433
|
+
var setB = new Set();
|
434
|
+
setB.add(setB1);
|
435
|
+
setB.add(setB2);
|
436
|
+
|
437
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
438
|
+
});
|
439
|
+
|
440
|
+
it("passes when comparing identical sets with different insertion order and complex elements 2", function() {
|
441
|
+
jasmine.getEnv().requireFunctioningSets();
|
442
|
+
|
443
|
+
var setA = new Set();
|
444
|
+
setA.add([[1,2], [3,4]]);
|
445
|
+
setA.add([[5,6], [7,8]]);
|
446
|
+
var setB = new Set();
|
447
|
+
setB.add([[5,6], [7,8]]);
|
448
|
+
setB.add([[1,2], [3,4]]);
|
449
|
+
|
450
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
451
|
+
});
|
452
|
+
|
453
|
+
it("fails for sets with different elements", function() {
|
454
|
+
jasmine.getEnv().requireFunctioningSets();
|
455
|
+
var setA = new Set();
|
456
|
+
setA.add(6);
|
457
|
+
setA.add(3);
|
458
|
+
setA.add(5);
|
459
|
+
var setB = new Set();
|
460
|
+
setB.add(6);
|
461
|
+
setB.add(4);
|
462
|
+
setB.add(5);
|
463
|
+
|
464
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
465
|
+
});
|
466
|
+
|
467
|
+
it("fails for sets of different size", function() {
|
468
|
+
jasmine.getEnv().requireFunctioningSets();
|
469
|
+
var setA = new Set();
|
470
|
+
setA.add(6);
|
471
|
+
setA.add(3);
|
472
|
+
var setB = new Set();
|
473
|
+
setB.add(6);
|
474
|
+
setB.add(4);
|
475
|
+
setB.add(5);
|
476
|
+
|
477
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
478
|
+
});
|
479
|
+
|
480
|
+
it("passes when comparing two empty maps", function() {
|
481
|
+
jasmine.getEnv().requireFunctioningMaps();
|
482
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Map(), new Map())).toBe(true);
|
483
|
+
});
|
484
|
+
|
485
|
+
it("passes when comparing identical maps", function() {
|
486
|
+
jasmine.getEnv().requireFunctioningMaps();
|
487
|
+
var mapA = new Map();
|
488
|
+
mapA.set(6, 5);
|
489
|
+
var mapB = new Map();
|
490
|
+
mapB.set(6, 5);
|
491
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
492
|
+
});
|
493
|
+
|
494
|
+
it("passes when comparing identical maps with different insertion order", function() {
|
495
|
+
jasmine.getEnv().requireFunctioningMaps();
|
496
|
+
var mapA = new Map();
|
497
|
+
mapA.set("a", 3);
|
498
|
+
mapA.set(6, 1);
|
499
|
+
var mapB = new Map();
|
500
|
+
mapB.set(6, 1);
|
501
|
+
mapB.set("a", 3);
|
502
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
503
|
+
});
|
504
|
+
|
505
|
+
it("fails for maps with different elements", function() {
|
506
|
+
jasmine.getEnv().requireFunctioningMaps();
|
507
|
+
var mapA = new Map();
|
508
|
+
mapA.set(6, 3);
|
509
|
+
mapA.set(5, 1);
|
510
|
+
var mapB = new Map();
|
511
|
+
mapB.set(6, 4);
|
512
|
+
mapB.set(5, 1);
|
513
|
+
|
514
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
515
|
+
});
|
516
|
+
|
517
|
+
it("fails for maps of different size", function() {
|
518
|
+
jasmine.getEnv().requireFunctioningMaps();
|
519
|
+
var mapA = new Map();
|
520
|
+
mapA.set(6, 3);
|
521
|
+
var mapB = new Map();
|
522
|
+
mapB.set(6, 4);
|
523
|
+
mapB.set(5, 1);
|
524
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
525
|
+
});
|
526
|
+
|
527
|
+
describe("when running in an environment with array polyfills", function() {
|
528
|
+
var findIndexDescriptor = Object.getOwnPropertyDescriptor(Array.prototype, 'findIndex');
|
529
|
+
if (!findIndexDescriptor) {
|
530
|
+
return;
|
531
|
+
}
|
532
|
+
|
533
|
+
beforeEach(function() {
|
534
|
+
Object.defineProperty(Array.prototype, 'findIndex', {
|
535
|
+
enumerable: true,
|
536
|
+
value: function (predicate) {
|
537
|
+
if (this === null) {
|
538
|
+
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
539
|
+
}
|
540
|
+
|
541
|
+
if (typeof predicate !== 'function') {
|
542
|
+
throw new TypeError('predicate must be a function');
|
543
|
+
}
|
544
|
+
|
545
|
+
var list = Object(this);
|
546
|
+
var length = list.length >>> 0;
|
547
|
+
var thisArg = arguments[1];
|
548
|
+
var value;
|
549
|
+
|
550
|
+
for (var i = 0; i < length; i++) {
|
551
|
+
value = list[i];
|
552
|
+
if (predicate.call(thisArg, value, i, list)) {
|
553
|
+
return i;
|
554
|
+
}
|
555
|
+
}
|
556
|
+
|
557
|
+
return -1;
|
558
|
+
}
|
559
|
+
});
|
560
|
+
});
|
561
|
+
|
562
|
+
afterEach(function() {
|
563
|
+
Object.defineProperty(Array.prototype, 'findIndex', findIndexDescriptor);
|
564
|
+
});
|
565
|
+
|
566
|
+
it("passes when there's an array polyfill", function() {
|
567
|
+
expect(['foo']).toEqual(['foo']);
|
568
|
+
});
|
569
|
+
});
|
570
|
+
});
|
571
|
+
|
572
|
+
describe("contains", function() {
|
573
|
+
it("passes when expected is a substring of actual", function() {
|
574
|
+
expect(jasmineUnderTest.matchersUtil.contains("ABC", "BC")).toBe(true);
|
575
|
+
});
|
576
|
+
|
577
|
+
it("fails when expected is a not substring of actual", function() {
|
578
|
+
expect(jasmineUnderTest.matchersUtil.contains("ABC", "X")).toBe(false);
|
579
|
+
});
|
580
|
+
|
581
|
+
it("passes when expected is an element in an actual array", function() {
|
582
|
+
expect(jasmineUnderTest.matchersUtil.contains(['foo', 'bar'], 'foo')).toBe(true);
|
583
|
+
});
|
584
|
+
|
585
|
+
it("fails when expected is not an element in an actual array", function() {
|
586
|
+
expect(jasmineUnderTest.matchersUtil.contains(['foo', 'bar'], 'baz')).toBe(false);
|
587
|
+
});
|
588
|
+
|
589
|
+
it("passes with mixed-element arrays", function() {
|
590
|
+
expect(jasmineUnderTest.matchersUtil.contains(["foo", {some: "bar"}], "foo")).toBe(true);
|
591
|
+
expect(jasmineUnderTest.matchersUtil.contains(["foo", {some: "bar"}], {some: "bar"})).toBe(true);
|
592
|
+
});
|
593
|
+
|
594
|
+
it("uses custom equality testers if passed in and actual is an Array", function() {
|
595
|
+
var customTester = function(a, b) {return true;};
|
596
|
+
|
597
|
+
expect(jasmineUnderTest.matchersUtil.contains([1, 2], 2, [customTester])).toBe(true);
|
598
|
+
});
|
599
|
+
|
600
|
+
it("fails when actual is undefined", function() {
|
601
|
+
expect(jasmineUnderTest.matchersUtil.contains(undefined, 'A')).toBe(false);
|
602
|
+
});
|
603
|
+
|
604
|
+
it("fails when actual is null", function() {
|
605
|
+
expect(jasmineUnderTest.matchersUtil.contains(null, 'A')).toBe(false);
|
606
|
+
});
|
607
|
+
|
608
|
+
it("passes with array-like objects", function() {
|
609
|
+
var capturedArgs = null;
|
610
|
+
function testFunction(){
|
611
|
+
capturedArgs = arguments;
|
612
|
+
}
|
613
|
+
testFunction('foo', 'bar');
|
614
|
+
expect(jasmineUnderTest.matchersUtil.contains(capturedArgs, 'bar')).toBe(true);
|
615
|
+
});
|
616
|
+
});
|
617
|
+
|
618
|
+
describe("buildMessage", function() {
|
619
|
+
|
620
|
+
it("builds an English sentence for a failure case", function() {
|
621
|
+
var actual = "foo",
|
622
|
+
name = "toBar",
|
623
|
+
message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, false, actual);
|
624
|
+
|
625
|
+
expect(message).toEqual("Expected 'foo' to bar.");
|
626
|
+
});
|
627
|
+
|
628
|
+
it("builds an English sentence for a 'not' failure case", function() {
|
629
|
+
var actual = "foo",
|
630
|
+
name = "toBar",
|
631
|
+
isNot = true,
|
632
|
+
message = message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, isNot, actual);
|
633
|
+
|
634
|
+
expect(message).toEqual("Expected 'foo' not to bar.");
|
635
|
+
});
|
636
|
+
|
637
|
+
it("builds an English sentence for an arbitrary array of expected arguments", function() {
|
638
|
+
var actual = "foo",
|
639
|
+
name = "toBar",
|
640
|
+
message = jasmineUnderTest.matchersUtil.buildFailureMessage(name, false, actual, "quux", "corge");
|
641
|
+
|
642
|
+
expect(message).toEqual("Expected 'foo' to bar 'quux', 'corge'.");
|
643
|
+
});
|
644
|
+
});
|
645
|
+
});
|