jasmine-core 2.5.0 → 2.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/console/console.js +1 -1
- data/lib/jasmine-core/boot/boot.js +4 -1
- data/lib/jasmine-core/boot.js +5 -2
- data/lib/jasmine-core/jasmine-html.js +95 -31
- data/lib/jasmine-core/jasmine.css +1 -0
- data/lib/jasmine-core/jasmine.js +3635 -1684
- data/lib/jasmine-core/node_boot.js +1 -1
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +10 -0
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +94 -14
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +26 -8
- data/lib/jasmine-core/spec/core/EnvSpec.js +142 -10
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +52 -7
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +132 -4
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +333 -23
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +16 -1
- data/lib/jasmine-core/spec/core/SpecSpec.js +30 -8
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +225 -1
- data/lib/jasmine-core/spec/core/SpySpec.js +44 -2
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +28 -5
- data/lib/jasmine-core/spec/core/SuiteSpec.js +14 -19
- data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +71 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +32 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +32 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +13 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +13 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +48 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +339 -38
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +156 -3
- data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
- data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +231 -8
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +42 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +780 -4
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +37 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +4 -0
- data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
- data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
- data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
- data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
- data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +105 -23
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +34 -0
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +1 -1
- data/lib/jasmine-core/version.rb +1 -1
- metadata +19 -4
@@ -172,6 +172,22 @@ describe("jasmine spec running", function () {
|
|
172
172
|
it("should run multiple befores and afters ordered so functions declared later are treated as more specific", function(done) {
|
173
173
|
var actions = [];
|
174
174
|
|
175
|
+
env.beforeAll(function() {
|
176
|
+
actions.push('runner beforeAll1');
|
177
|
+
});
|
178
|
+
|
179
|
+
env.afterAll(function() {
|
180
|
+
actions.push('runner afterAll1');
|
181
|
+
});
|
182
|
+
|
183
|
+
env.beforeAll(function() {
|
184
|
+
actions.push('runner beforeAll2');
|
185
|
+
});
|
186
|
+
|
187
|
+
env.afterAll(function() {
|
188
|
+
actions.push('runner afterAll2');
|
189
|
+
});
|
190
|
+
|
175
191
|
env.beforeEach(function () {
|
176
192
|
actions.push('runner beforeEach1');
|
177
193
|
});
|
@@ -212,6 +228,8 @@ describe("jasmine spec running", function () {
|
|
212
228
|
|
213
229
|
var assertions = function() {
|
214
230
|
var expected = [
|
231
|
+
"runner beforeAll1",
|
232
|
+
"runner beforeAll2",
|
215
233
|
"runner beforeEach1",
|
216
234
|
"runner beforeEach2",
|
217
235
|
"beforeEach1",
|
@@ -220,7 +238,9 @@ describe("jasmine spec running", function () {
|
|
220
238
|
"afterEach2",
|
221
239
|
"afterEach1",
|
222
240
|
"runner afterEach2",
|
223
|
-
"runner afterEach1"
|
241
|
+
"runner afterEach1",
|
242
|
+
"runner afterAll2",
|
243
|
+
"runner afterAll1"
|
224
244
|
];
|
225
245
|
expect(actions).toEqual(expected);
|
226
246
|
done();
|
@@ -475,7 +495,7 @@ describe("jasmine spec running", function () {
|
|
475
495
|
env.execute();
|
476
496
|
});
|
477
497
|
|
478
|
-
it('focused runnables unfocus ancestor focused suites', function() {
|
498
|
+
it('focused runnables unfocus ancestor focused suites', function(done) {
|
479
499
|
var actions = [];
|
480
500
|
|
481
501
|
env.fdescribe('focused suite', function() {
|
@@ -518,7 +538,29 @@ describe("jasmine spec running", function () {
|
|
518
538
|
env.execute();
|
519
539
|
});
|
520
540
|
|
521
|
-
it("
|
541
|
+
it("shouldn't run before/after functions in disabled suites", function(done) {
|
542
|
+
var shouldNotRun = jasmine.createSpy("shouldNotRun"),
|
543
|
+
suite = env.xdescribe('A disabled Suite', function() {
|
544
|
+
// None of the before/after functions should run.
|
545
|
+
env.beforeAll(shouldNotRun);
|
546
|
+
env.beforeEach(shouldNotRun);
|
547
|
+
env.afterEach(shouldNotRun);
|
548
|
+
env.afterAll(shouldNotRun);
|
549
|
+
|
550
|
+
env.it('spec inside a disabled suite', shouldNotRun);
|
551
|
+
});
|
552
|
+
|
553
|
+
var assertions = function() {
|
554
|
+
expect(shouldNotRun).not.toHaveBeenCalled();
|
555
|
+
done();
|
556
|
+
};
|
557
|
+
|
558
|
+
env.addReporter({jasmineDone: assertions});
|
559
|
+
|
560
|
+
env.execute();
|
561
|
+
});
|
562
|
+
|
563
|
+
it("should allow top level suites to be disabled", function(done) {
|
522
564
|
var specInADisabledSuite = jasmine.createSpy("specInADisabledSuite"),
|
523
565
|
otherSpec = jasmine.createSpy("otherSpec");
|
524
566
|
|
@@ -794,4 +836,115 @@ describe("jasmine spec running", function () {
|
|
794
836
|
env.execute();
|
795
837
|
});
|
796
838
|
|
839
|
+
describe("When throwOnExpectationFailure is set", function() {
|
840
|
+
it("skips to cleanup functions after an error", function(done) {
|
841
|
+
var actions = [];
|
842
|
+
|
843
|
+
env.describe('Something', function() {
|
844
|
+
env.beforeEach(function() {
|
845
|
+
actions.push('outer beforeEach');
|
846
|
+
throw new Error("error");
|
847
|
+
});
|
848
|
+
|
849
|
+
env.afterEach(function() {
|
850
|
+
actions.push('outer afterEach');
|
851
|
+
});
|
852
|
+
|
853
|
+
env.describe('Inner', function() {
|
854
|
+
env.beforeEach(function() {
|
855
|
+
actions.push('inner beforeEach');
|
856
|
+
});
|
857
|
+
|
858
|
+
env.afterEach(function() {
|
859
|
+
actions.push('inner afterEach');
|
860
|
+
});
|
861
|
+
|
862
|
+
env.it('does it' , function() {
|
863
|
+
actions.push('inner it');
|
864
|
+
});
|
865
|
+
});
|
866
|
+
});
|
867
|
+
|
868
|
+
env.throwOnExpectationFailure(true);
|
869
|
+
|
870
|
+
var assertions = function() {
|
871
|
+
expect(actions).toEqual([
|
872
|
+
'outer beforeEach',
|
873
|
+
'inner afterEach',
|
874
|
+
'outer afterEach'
|
875
|
+
]);
|
876
|
+
done();
|
877
|
+
};
|
878
|
+
|
879
|
+
env.addReporter({jasmineDone: assertions});
|
880
|
+
|
881
|
+
env.execute();
|
882
|
+
});
|
883
|
+
|
884
|
+
it("skips to cleanup functions after done.fail is called", function(done) {
|
885
|
+
var actions = [];
|
886
|
+
|
887
|
+
env.describe('Something', function() {
|
888
|
+
env.beforeEach(function(done) {
|
889
|
+
actions.push('beforeEach');
|
890
|
+
done.fail('error');
|
891
|
+
actions.push('after done.fail');
|
892
|
+
});
|
893
|
+
|
894
|
+
env.afterEach(function() {
|
895
|
+
actions.push('afterEach');
|
896
|
+
});
|
897
|
+
|
898
|
+
env.it('does it' , function() {
|
899
|
+
actions.push('it');
|
900
|
+
});
|
901
|
+
});
|
902
|
+
|
903
|
+
env.throwOnExpectationFailure(true);
|
904
|
+
|
905
|
+
var assertions = function() {
|
906
|
+
expect(actions).toEqual([
|
907
|
+
'beforeEach',
|
908
|
+
'afterEach'
|
909
|
+
]);
|
910
|
+
done();
|
911
|
+
};
|
912
|
+
|
913
|
+
env.addReporter({jasmineDone: assertions});
|
914
|
+
|
915
|
+
env.execute();
|
916
|
+
});
|
917
|
+
|
918
|
+
it("skips to cleanup functions when an async function times out", function(done) {
|
919
|
+
var actions = [];
|
920
|
+
|
921
|
+
env.describe('Something', function() {
|
922
|
+
env.beforeEach(function(innerDone) {
|
923
|
+
actions.push('beforeEach');
|
924
|
+
}, 1);
|
925
|
+
|
926
|
+
env.afterEach(function() {
|
927
|
+
actions.push('afterEach');
|
928
|
+
});
|
929
|
+
|
930
|
+
env.it('does it' , function() {
|
931
|
+
actions.push('it');
|
932
|
+
});
|
933
|
+
});
|
934
|
+
|
935
|
+
env.throwOnExpectationFailure(true);
|
936
|
+
|
937
|
+
var assertions = function() {
|
938
|
+
expect(actions).toEqual([
|
939
|
+
'beforeEach',
|
940
|
+
'afterEach'
|
941
|
+
]);
|
942
|
+
done();
|
943
|
+
};
|
944
|
+
|
945
|
+
env.addReporter({jasmineDone: assertions});
|
946
|
+
|
947
|
+
env.execute();
|
948
|
+
});
|
949
|
+
});
|
797
950
|
});
|
@@ -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
|
+
});
|
@@ -61,13 +61,17 @@ describe("matchersUtil", function() {
|
|
61
61
|
expect(jasmineUnderTest.matchersUtil.equals(foo, [undefined])).toBe(true);
|
62
62
|
});
|
63
63
|
|
64
|
-
it("fails for Arrays that
|
64
|
+
it("fails for Arrays that have different lengths", function() {
|
65
65
|
expect(jasmineUnderTest.matchersUtil.equals([1, 2], [1, 2, 3])).toBe(false);
|
66
66
|
});
|
67
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
|
+
|
68
72
|
it("fails for Arrays whose contents are equivalent, but have differing properties", function() {
|
69
73
|
var one = [1,2,3],
|
70
|
-
|
74
|
+
two = [1,2,3];
|
71
75
|
|
72
76
|
one.foo = 'bar';
|
73
77
|
two.foo = 'baz';
|
@@ -77,7 +81,7 @@ describe("matchersUtil", function() {
|
|
77
81
|
|
78
82
|
it("passes for Arrays with equivalent contents and properties", function() {
|
79
83
|
var one = [1,2,3],
|
80
|
-
|
84
|
+
two = [1,2,3];
|
81
85
|
|
82
86
|
one.foo = 'bar';
|
83
87
|
two.foo = 'bar';
|
@@ -118,7 +122,7 @@ describe("matchersUtil", function() {
|
|
118
122
|
|
119
123
|
it("passes for Objects that are equivalent (with cycles)", function() {
|
120
124
|
var actual = { a: "foo" },
|
121
|
-
|
125
|
+
expected = { a: "foo" };
|
122
126
|
|
123
127
|
actual.b = actual;
|
124
128
|
expected.b = actual;
|
@@ -136,6 +140,13 @@ describe("matchersUtil", function() {
|
|
136
140
|
expect(jasmineUnderTest.matchersUtil.equals(actual, expected)).toBe(false);
|
137
141
|
});
|
138
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
|
+
|
139
150
|
it("fails when comparing an empty object to an empty array (issue #114)", function() {
|
140
151
|
var emptyObject = {},
|
141
152
|
emptyArray = [];
|
@@ -155,6 +166,16 @@ describe("matchersUtil", function() {
|
|
155
166
|
|
156
167
|
expect(jasmineUnderTest.matchersUtil.equals(a,b)).toBe(true);
|
157
168
|
});
|
169
|
+
|
170
|
+
it("passes for equivalent Promises (GitHub issue #1314)", function() {
|
171
|
+
if (typeof Promise === 'undefined') { return; }
|
172
|
+
|
173
|
+
var p1 = new Promise(function () {}),
|
174
|
+
p2 = new Promise(function () {});
|
175
|
+
|
176
|
+
expect(jasmineUnderTest.matchersUtil.equals(p1, p1)).toBe(true);
|
177
|
+
expect(jasmineUnderTest.matchersUtil.equals(p1, p2)).toBe(false);
|
178
|
+
});
|
158
179
|
|
159
180
|
describe("when running in a browser", function() {
|
160
181
|
function isNotRunningInBrowser() {
|
@@ -321,15 +342,25 @@ describe("matchersUtil", function() {
|
|
321
342
|
|
322
343
|
it("passes for an asymmetric equality tester that returns true when a custom equality tester return false", function() {
|
323
344
|
var asymmetricTester = { asymmetricMatch: function(other) { return true; } },
|
324
|
-
|
345
|
+
symmetricTester = function(a, b) { return false; };
|
325
346
|
|
326
347
|
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, true, [symmetricTester])).toBe(true);
|
327
348
|
expect(jasmineUnderTest.matchersUtil.equals(true, asymmetricTester, [symmetricTester])).toBe(true);
|
328
349
|
});
|
329
350
|
|
351
|
+
it("passes custom equality matchers to asymmetric equality testers", function() {
|
352
|
+
var tester = function(a, b) {};
|
353
|
+
var asymmetricTester = { asymmetricMatch: jasmine.createSpy('asymmetricMatch') };
|
354
|
+
asymmetricTester.asymmetricMatch.and.returnValue(true);
|
355
|
+
var other = {};
|
356
|
+
|
357
|
+
expect(jasmineUnderTest.matchersUtil.equals(asymmetricTester, other, [tester])).toBe(true);
|
358
|
+
expect(asymmetricTester.asymmetricMatch).toHaveBeenCalledWith(other, [tester]);
|
359
|
+
});
|
360
|
+
|
330
361
|
it("passes when an Any is compared to an Any that checks for the same type", function() {
|
331
362
|
var any1 = new jasmineUnderTest.Any(Function),
|
332
|
-
|
363
|
+
any2 = new jasmineUnderTest.Any(Function);
|
333
364
|
|
334
365
|
expect(jasmineUnderTest.matchersUtil.equals(any1, any2)).toBe(true);
|
335
366
|
});
|
@@ -338,7 +369,7 @@ describe("matchersUtil", function() {
|
|
338
369
|
if (jasmine.getEnv().ieVersion < 9) { return; }
|
339
370
|
|
340
371
|
var objA = Object.create(null),
|
341
|
-
|
372
|
+
objB = Object.create(null);
|
342
373
|
|
343
374
|
objA.name = 'test';
|
344
375
|
objB.name = 'test';
|
@@ -350,13 +381,205 @@ describe("matchersUtil", function() {
|
|
350
381
|
if (jasmine.getEnv().ieVersion < 9) { return; }
|
351
382
|
|
352
383
|
var objA = Object.create(null),
|
353
|
-
|
384
|
+
objB = Object.create(null);
|
354
385
|
|
355
386
|
objA.name = 'test';
|
356
387
|
objB.test = 'name';
|
357
388
|
|
358
389
|
expect(jasmineUnderTest.matchersUtil.equals(objA, objB)).toBe(false);
|
359
390
|
});
|
391
|
+
|
392
|
+
it("passes when comparing two empty sets", function() {
|
393
|
+
jasmine.getEnv().requireFunctioningSets();
|
394
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Set(), new Set())).toBe(true);
|
395
|
+
});
|
396
|
+
|
397
|
+
it("passes when comparing identical sets", function() {
|
398
|
+
jasmine.getEnv().requireFunctioningSets();
|
399
|
+
|
400
|
+
var setA = new Set();
|
401
|
+
setA.add(6);
|
402
|
+
setA.add(5);
|
403
|
+
var setB = new Set();
|
404
|
+
setB.add(6);
|
405
|
+
setB.add(5);
|
406
|
+
|
407
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
408
|
+
});
|
409
|
+
|
410
|
+
it("passes when comparing identical sets with different insertion order and simple elements", function() {
|
411
|
+
jasmine.getEnv().requireFunctioningSets();
|
412
|
+
|
413
|
+
var setA = new Set();
|
414
|
+
setA.add(3);
|
415
|
+
setA.add(6);
|
416
|
+
var setB = new Set();
|
417
|
+
setB.add(6);
|
418
|
+
setB.add(3);
|
419
|
+
|
420
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
421
|
+
});
|
422
|
+
|
423
|
+
it("passes when comparing identical sets with different insertion order and complex elements 1", function() {
|
424
|
+
jasmine.getEnv().requireFunctioningSets();
|
425
|
+
|
426
|
+
var setA1 = new Set();
|
427
|
+
setA1.add(['a',3]);
|
428
|
+
setA1.add([6,1]);
|
429
|
+
var setA2 = new Set();
|
430
|
+
setA1.add(['y',3]);
|
431
|
+
setA1.add([6,1]);
|
432
|
+
var setA = new Set();
|
433
|
+
setA.add(setA1);
|
434
|
+
setA.add(setA2);
|
435
|
+
|
436
|
+
|
437
|
+
var setB1 = new Set();
|
438
|
+
setB1.add([6,1]);
|
439
|
+
setB1.add(['a',3]);
|
440
|
+
var setB2 = new Set();
|
441
|
+
setB1.add([6,1]);
|
442
|
+
setB1.add(['y',3]);
|
443
|
+
var setB = new Set();
|
444
|
+
setB.add(setB1);
|
445
|
+
setB.add(setB2);
|
446
|
+
|
447
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
448
|
+
});
|
449
|
+
|
450
|
+
it("passes when comparing identical sets with different insertion order and complex elements 2", function() {
|
451
|
+
jasmine.getEnv().requireFunctioningSets();
|
452
|
+
|
453
|
+
var setA = new Set();
|
454
|
+
setA.add([[1,2], [3,4]]);
|
455
|
+
setA.add([[5,6], [7,8]]);
|
456
|
+
var setB = new Set();
|
457
|
+
setB.add([[5,6], [7,8]]);
|
458
|
+
setB.add([[1,2], [3,4]]);
|
459
|
+
|
460
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(true);
|
461
|
+
});
|
462
|
+
|
463
|
+
it("fails for sets with different elements", function() {
|
464
|
+
jasmine.getEnv().requireFunctioningSets();
|
465
|
+
var setA = new Set();
|
466
|
+
setA.add(6);
|
467
|
+
setA.add(3);
|
468
|
+
setA.add(5);
|
469
|
+
var setB = new Set();
|
470
|
+
setB.add(6);
|
471
|
+
setB.add(4);
|
472
|
+
setB.add(5);
|
473
|
+
|
474
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
475
|
+
});
|
476
|
+
|
477
|
+
it("fails for sets of different size", function() {
|
478
|
+
jasmine.getEnv().requireFunctioningSets();
|
479
|
+
var setA = new Set();
|
480
|
+
setA.add(6);
|
481
|
+
setA.add(3);
|
482
|
+
var setB = new Set();
|
483
|
+
setB.add(6);
|
484
|
+
setB.add(4);
|
485
|
+
setB.add(5);
|
486
|
+
|
487
|
+
expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
|
488
|
+
});
|
489
|
+
|
490
|
+
it("passes when comparing two empty maps", function() {
|
491
|
+
jasmine.getEnv().requireFunctioningMaps();
|
492
|
+
expect(jasmineUnderTest.matchersUtil.equals(new Map(), new Map())).toBe(true);
|
493
|
+
});
|
494
|
+
|
495
|
+
it("passes when comparing identical maps", function() {
|
496
|
+
jasmine.getEnv().requireFunctioningMaps();
|
497
|
+
var mapA = new Map();
|
498
|
+
mapA.set(6, 5);
|
499
|
+
var mapB = new Map();
|
500
|
+
mapB.set(6, 5);
|
501
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
502
|
+
});
|
503
|
+
|
504
|
+
it("passes when comparing identical maps with different insertion order", function() {
|
505
|
+
jasmine.getEnv().requireFunctioningMaps();
|
506
|
+
var mapA = new Map();
|
507
|
+
mapA.set("a", 3);
|
508
|
+
mapA.set(6, 1);
|
509
|
+
var mapB = new Map();
|
510
|
+
mapB.set(6, 1);
|
511
|
+
mapB.set("a", 3);
|
512
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
|
513
|
+
});
|
514
|
+
|
515
|
+
it("fails for maps with different elements", function() {
|
516
|
+
jasmine.getEnv().requireFunctioningMaps();
|
517
|
+
var mapA = new Map();
|
518
|
+
mapA.set(6, 3);
|
519
|
+
mapA.set(5, 1);
|
520
|
+
var mapB = new Map();
|
521
|
+
mapB.set(6, 4);
|
522
|
+
mapB.set(5, 1);
|
523
|
+
|
524
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
525
|
+
});
|
526
|
+
|
527
|
+
it("fails for maps of different size", function() {
|
528
|
+
jasmine.getEnv().requireFunctioningMaps();
|
529
|
+
var mapA = new Map();
|
530
|
+
mapA.set(6, 3);
|
531
|
+
var mapB = new Map();
|
532
|
+
mapB.set(6, 4);
|
533
|
+
mapB.set(5, 1);
|
534
|
+
expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
|
535
|
+
});
|
536
|
+
|
537
|
+
describe("when running in an environment with array polyfills", function() {
|
538
|
+
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
539
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
540
|
+
|
541
|
+
var findIndexDescriptor = Object.getOwnPropertyDescriptor(Array.prototype, 'findIndex');
|
542
|
+
if (!findIndexDescriptor) {
|
543
|
+
return;
|
544
|
+
}
|
545
|
+
|
546
|
+
beforeEach(function() {
|
547
|
+
Object.defineProperty(Array.prototype, 'findIndex', {
|
548
|
+
enumerable: true,
|
549
|
+
value: function (predicate) {
|
550
|
+
if (this === null) {
|
551
|
+
throw new TypeError('Array.prototype.findIndex called on null or undefined');
|
552
|
+
}
|
553
|
+
|
554
|
+
if (typeof predicate !== 'function') {
|
555
|
+
throw new TypeError('predicate must be a function');
|
556
|
+
}
|
557
|
+
|
558
|
+
var list = Object(this);
|
559
|
+
var length = list.length >>> 0;
|
560
|
+
var thisArg = arguments[1];
|
561
|
+
var value;
|
562
|
+
|
563
|
+
for (var i = 0; i < length; i++) {
|
564
|
+
value = list[i];
|
565
|
+
if (predicate.call(thisArg, value, i, list)) {
|
566
|
+
return i;
|
567
|
+
}
|
568
|
+
}
|
569
|
+
|
570
|
+
return -1;
|
571
|
+
}
|
572
|
+
});
|
573
|
+
});
|
574
|
+
|
575
|
+
afterEach(function() {
|
576
|
+
Object.defineProperty(Array.prototype, 'findIndex', findIndexDescriptor);
|
577
|
+
});
|
578
|
+
|
579
|
+
it("passes when there's an array polyfill", function() {
|
580
|
+
expect(['foo']).toEqual(['foo']);
|
581
|
+
});
|
582
|
+
});
|
360
583
|
});
|
361
584
|
|
362
585
|
describe("contains", function() {
|
@@ -8,6 +8,9 @@ describe("toBeCloseTo", function() {
|
|
8
8
|
|
9
9
|
result = matcher.compare(0, 0.001);
|
10
10
|
expect(result.pass).toBe(true);
|
11
|
+
|
12
|
+
result = matcher.compare(0, 0.005);
|
13
|
+
expect(result.pass).toBe(true);
|
11
14
|
});
|
12
15
|
|
13
16
|
it("fails when not within two decimal places by default", function() {
|
@@ -16,6 +19,9 @@ describe("toBeCloseTo", function() {
|
|
16
19
|
|
17
20
|
result = matcher.compare(0, 0.01);
|
18
21
|
expect(result.pass).toBe(false);
|
22
|
+
|
23
|
+
result = matcher.compare(0, 0.05);
|
24
|
+
expect(result.pass).toBe(false);
|
19
25
|
});
|
20
26
|
|
21
27
|
it("accepts an optional precision argument", function() {
|
@@ -25,8 +31,36 @@ describe("toBeCloseTo", function() {
|
|
25
31
|
result = matcher.compare(0, 0.1, 0);
|
26
32
|
expect(result.pass).toBe(true);
|
27
33
|
|
34
|
+
result = matcher.compare(0, 0.5, 0);
|
35
|
+
expect(result.pass).toBe(true);
|
36
|
+
|
28
37
|
result = matcher.compare(0, 0.0001, 3);
|
29
38
|
expect(result.pass).toBe(true);
|
39
|
+
|
40
|
+
result = matcher.compare(0, 0.0005, 3);
|
41
|
+
expect(result.pass).toBe(true);
|
42
|
+
|
43
|
+
result = matcher.compare(0, 0.00001, 4);
|
44
|
+
expect(result.pass).toBe(true);
|
45
|
+
|
46
|
+
result = matcher.compare(0, 0.00005, 4);
|
47
|
+
expect(result.pass).toBe(true);
|
48
|
+
});
|
49
|
+
|
50
|
+
it("fails when one of the arguments is null", function() {
|
51
|
+
var matcher = jasmineUnderTest.matchers.toBeCloseTo();
|
52
|
+
|
53
|
+
expect(function() {
|
54
|
+
matcher.compare(null, null);
|
55
|
+
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(null).');
|
56
|
+
|
57
|
+
expect(function() {
|
58
|
+
matcher.compare(0, null);
|
59
|
+
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(0).toBeCloseTo(null).');
|
60
|
+
|
61
|
+
expect(function() {
|
62
|
+
matcher.compare(null, 0);
|
63
|
+
}).toThrowError('Cannot use toBeCloseTo with null. Arguments evaluated to: expect(null).toBeCloseTo(0).');
|
30
64
|
});
|
31
65
|
|
32
66
|
it("rounds expected values", function() {
|
@@ -42,7 +76,15 @@ describe("toBeCloseTo", function() {
|
|
42
76
|
result = matcher.compare(1.23, 1.225);
|
43
77
|
expect(result.pass).toBe(true);
|
44
78
|
|
79
|
+
result = matcher.compare(1.23, 1.235);
|
80
|
+
expect(result.pass).toBe(true);
|
81
|
+
|
82
|
+
// 1.2249999 will be rounded to 1.225
|
45
83
|
result = matcher.compare(1.23, 1.2249999);
|
84
|
+
expect(result.pass).toBe(true);
|
85
|
+
|
86
|
+
// 1.2249999 will be rounded to 1.224
|
87
|
+
result = matcher.compare(1.23, 1.2244999);
|
46
88
|
expect(result.pass).toBe(false);
|
47
89
|
|
48
90
|
result = matcher.compare(1.23, 1.234);
|