jasmine-core 2.6.4 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -141,5 +141,15 @@ describe("Suite", function() {
141
141
  suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
142
142
 
143
143
  expect(suite.getResult().failedExpectations).toEqual([]);
144
- })
144
+ });
145
+
146
+ describe('#sharedUserContext', function() {
147
+ beforeEach(function() {
148
+ this.suite = new jasmineUnderTest.Suite({});
149
+ });
150
+
151
+ it('returns a UserContext', function() {
152
+ expect(this.suite.sharedUserContext().constructor).toBe(jasmineUnderTest.UserContext);
153
+ });
154
+ });
145
155
  });
@@ -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
+
@@ -243,7 +243,7 @@ describe("Env integration", function() {
243
243
  } else {
244
244
  secondSpecContext = this;
245
245
  }
246
- expect(this).toEqual({});
246
+ expect(this).toEqual(new jasmineUnderTest.UserContext());
247
247
  });
248
248
 
249
249
  env.it("sync spec", function() {
@@ -277,7 +277,7 @@ describe("Env integration", function() {
277
277
 
278
278
  env.beforeEach(function() {
279
279
  specContext = this;
280
- expect(this).toEqual({});
280
+ expect(this).toEqual(new jasmineUnderTest.UserContext());
281
281
  });
282
282
 
283
283
  env.it("sync spec", function(underTestCallback) {
@@ -1069,7 +1069,6 @@ describe("Env integration", function() {
1069
1069
  env.afterAll(function(innerDone) {
1070
1070
  jasmine.clock().tick(3001);
1071
1071
  innerDone();
1072
- jasmine.clock().tick(1);
1073
1072
  });
1074
1073
  });
1075
1074
 
@@ -1300,7 +1299,8 @@ describe("Env integration", function() {
1300
1299
 
1301
1300
  reporter.jasmineDone.and.callFake(function() {
1302
1301
  expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1303
- totalSpecsDefined: 1
1302
+ totalSpecsDefined: 1,
1303
+ order: jasmine.any(jasmineUnderTest.Order)
1304
1304
  });
1305
1305
 
1306
1306
  expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
@@ -1335,7 +1335,8 @@ describe("Env integration", function() {
1335
1335
 
1336
1336
  reporter.jasmineDone.and.callFake(function() {
1337
1337
  expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1338
- totalSpecsDefined: 1
1338
+ totalSpecsDefined: 1,
1339
+ order: jasmine.any(jasmineUnderTest.Order)
1339
1340
  });
1340
1341
 
1341
1342
  expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
@@ -1373,7 +1374,8 @@ describe("Env integration", function() {
1373
1374
 
1374
1375
  reporter.jasmineDone.and.callFake(function() {
1375
1376
  expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1376
- totalSpecsDefined: 5
1377
+ totalSpecsDefined: 5,
1378
+ order: jasmine.any(jasmineUnderTest.Order)
1377
1379
  });
1378
1380
 
1379
1381
  expect(reporter.specDone.calls.count()).toBe(5);
@@ -1430,6 +1432,34 @@ describe("Env integration", function() {
1430
1432
  env.execute();
1431
1433
  });
1432
1434
 
1435
+ it("should report the random seed at the beginning and end of execution", function(done) {
1436
+ var env = new jasmineUnderTest.Env(),
1437
+ reporter = jasmine.createSpyObj('fakeReporter', [
1438
+ "jasmineStarted",
1439
+ "jasmineDone",
1440
+ "suiteStarted",
1441
+ "suiteDone",
1442
+ "specStarted",
1443
+ "specDone"
1444
+ ]);
1445
+ env.randomizeTests(true);
1446
+ env.seed('123456');
1447
+
1448
+ reporter.jasmineDone.and.callFake(function(doneArg) {
1449
+ expect(reporter.jasmineStarted).toHaveBeenCalled();
1450
+ var startedArg = reporter.jasmineStarted.calls.argsFor(0)[0];
1451
+ expect(startedArg.order.random).toEqual(true);
1452
+ expect(startedArg.order.seed).toEqual('123456');
1453
+
1454
+ expect(doneArg.order.random).toEqual(true);
1455
+ expect(doneArg.order.seed).toEqual('123456');
1456
+ done();
1457
+ });
1458
+
1459
+ env.addReporter(reporter);
1460
+ env.execute();
1461
+ });
1462
+
1433
1463
  it('should report pending spec messages', function(done) {
1434
1464
  var env = new jasmineUnderTest.Env(),
1435
1465
  reporter = jasmine.createSpyObj('fakeReporter', [
@@ -1489,7 +1519,8 @@ describe("Env integration", function() {
1489
1519
 
1490
1520
  reporter.jasmineDone.and.callFake(function() {
1491
1521
  expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1492
- totalSpecsDefined: 1
1522
+ totalSpecsDefined: 1,
1523
+ order: jasmine.any(jasmineUnderTest.Order)
1493
1524
  });
1494
1525
 
1495
1526
  expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'disabled' }));
@@ -836,4 +836,115 @@ describe("jasmine spec running", function () {
836
836
  env.execute();
837
837
  });
838
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
+ });
839
950
  });
@@ -414,6 +414,40 @@ describe("matchersUtil", function() {
414
414
  expect(jasmineUnderTest.matchersUtil.equals(setA, setB)).toBe(false);
415
415
  });
416
416
 
417
+ it("passes when comparing two empty maps", function() {
418
+ jasmine.getEnv().requireFunctioningMaps();
419
+ expect(jasmineUnderTest.matchersUtil.equals(new Map(), new Map())).toBe(true);
420
+ });
421
+
422
+ it("passes when comparing identical maps", function() {
423
+ jasmine.getEnv().requireFunctioningMaps();
424
+ var mapA = new Map([[6, 5]]);
425
+ var mapB = new Map();
426
+ mapB.set(6, 5);
427
+ expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(true);
428
+ });
429
+
430
+ it("fails for maps with different elements", function() {
431
+ jasmine.getEnv().requireFunctioningMaps();
432
+ var mapA = new Map([[6, 3], [5, 1]]);
433
+ var mapB = new Map([[6, 4], [5, 1]]);
434
+ expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
435
+ });
436
+
437
+ it("fails for maps of different size", function() {
438
+ jasmine.getEnv().requireFunctioningMaps();
439
+ var mapA = new Map([[6, 3]]);
440
+ var mapB = new Map([[6, 4], [5, 1]]);
441
+ expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
442
+ });
443
+
444
+ it("fails for maps with different insertion order", function() {
445
+ jasmine.getEnv().requireFunctioningMaps();
446
+ var mapA = new Map([['a', 3], [6, 1]]);
447
+ var mapB = new Map([[6, 1], ['a', 3]]);
448
+ expect(jasmineUnderTest.matchersUtil.equals(mapA, mapB)).toBe(false);
449
+ });
450
+
417
451
  describe("when running in an environment with array polyfills", function() {
418
452
  // IE 8 doesn't support `definePropery` on non-DOM nodes
419
453
  if (jasmine.getEnv().ieVersion < 9) { return; }
@@ -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);
@@ -390,6 +390,37 @@ describe("toEqual", function() {
390
390
  expect(compareEquals(actual, expected).message).toEqual(message);
391
391
  });
392
392
 
393
+ it("does not report deep mismatches within Maps", function() {
394
+ // TODO: implement deep comparison of Map elements
395
+ jasmine.getEnv().requireFunctioningMaps();
396
+
397
+ var actual = new Map([['a', 1]]),
398
+ expected = new Map([['a', 2]]),
399
+ message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
400
+
401
+ expect(compareEquals(actual, expected).message).toEqual(message);
402
+ });
403
+
404
+ it("reports mismatches between Maps nested in objects", function() {
405
+ jasmine.getEnv().requireFunctioningMaps();
406
+
407
+ var actual = {Maps: [new Map([['a', 1]])]},
408
+ expected = {Maps: [new Map([['a', 2], ['b', 1]])]},
409
+ message = "Expected $.Maps[0] = Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ], [ 'b', 1 ] ).";
410
+
411
+ expect(compareEquals(actual, expected).message).toEqual(message);
412
+ });
413
+
414
+ it("reports mismatches between Maps of different lengths", function() {
415
+ jasmine.getEnv().requireFunctioningMaps();
416
+
417
+ var actual = new Map([['a', 1]]),
418
+ expected = new Map([['a', 2]]),
419
+ message = "Expected Map( [ 'a', 1 ] ) to equal Map( [ 'a', 2 ] ).";
420
+
421
+ expect(compareEquals(actual, expected).message).toEqual(message);
422
+ });
423
+
393
424
  function isNotRunningInBrowser() {
394
425
  return typeof document === 'undefined'
395
426
  }
@@ -0,0 +1,27 @@
1
+ (function(env) {
2
+ function getAsyncCtor() {
3
+ try {
4
+ eval("var func = async function(){};");
5
+ } catch (e) {
6
+ return null;
7
+ }
8
+
9
+ return Object.getPrototypeOf(func).constructor;
10
+ }
11
+
12
+ function hasAsyncAwaitSupport() {
13
+ return getAsyncCtor() !== null;
14
+ }
15
+
16
+ env.makeAsyncAwaitFunction = function() {
17
+ var AsyncFunction = getAsyncCtor();
18
+ return new AsyncFunction("");
19
+ };
20
+
21
+ env.requireAsyncAwait = function() {
22
+ if (!hasAsyncAwaitSupport()) {
23
+ env.pending("Environment does not support async/await functions");
24
+ }
25
+ };
26
+ })(jasmine.getEnv());
27
+