jasmine-core 2.3.4 → 2.4.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.
@@ -37,6 +37,35 @@ describe("SpyRegistry", function() {
37
37
  }).toThrowError(/has already been spied upon/);
38
38
  });
39
39
 
40
+ it("checks if it can be spied upon", function() {
41
+ // IE 8 doesn't support `definePropery` on non-DOM nodes
42
+ if (jasmine.getEnv().ieVersion < 9) { return; }
43
+
44
+ var scope = {};
45
+
46
+ function myFunc() {
47
+ return 1;
48
+ }
49
+
50
+ Object.defineProperty(scope, 'myFunc', {
51
+ get: function() {
52
+ return myFunc;
53
+ }
54
+ });
55
+
56
+ var spies = [],
57
+ spyRegistry = new j$.SpyRegistry({currentSpies: function() { return spies; }}),
58
+ subject = { spiedFunc: scope.myFunc };
59
+
60
+ expect(function() {
61
+ spyRegistry.spyOn(scope, 'myFunc');
62
+ }).toThrowError(/is not declared writable or has no setter/);
63
+
64
+ expect(function() {
65
+ spyRegistry.spyOn(subject, 'spiedFunc');
66
+ }).not.toThrowError(/is not declared writable or has no setter/);
67
+ });
68
+
40
69
  it("overrides the method on the object and returns the spy", function() {
41
70
  var originalFunctionWasCalled = false,
42
71
  spyRegistry = new j$.SpyRegistry(),
@@ -90,6 +90,21 @@ describe("Suite", function() {
90
90
  expect(suite.getResult().status).toBe('disabled');
91
91
  });
92
92
 
93
+ it("retrieves a result with pending status", function() {
94
+ var suite = new j$.Suite({});
95
+ suite.pend();
96
+
97
+ expect(suite.getResult().status).toBe('pending');
98
+ });
99
+
100
+ it("priviledges a disabled status over pending status", function() {
101
+ var suite = new j$.Suite({});
102
+ suite.disable();
103
+ suite.pend();
104
+
105
+ expect(suite.getResult().status).toBe('disabled');
106
+ });
107
+
93
108
  it("is executable if not disabled", function() {
94
109
  var suite = new j$.Suite({});
95
110
 
@@ -690,4 +690,67 @@ describe("TreeProcessor", function() {
690
690
  queueableFns[10].fn();
691
691
  expect(leaf11.execute).toHaveBeenCalled();
692
692
  });
693
+
694
+ it("runs nodes in a custom order when orderChildren is overrided", function() {
695
+ var leaf1 = new Leaf(),
696
+ leaf2 = new Leaf(),
697
+ leaf3 = new Leaf(),
698
+ leaf4 = new Leaf(),
699
+ leaf5 = new Leaf(),
700
+ leaf6 = new Leaf(),
701
+ leaf7 = new Leaf(),
702
+ leaf8 = new Leaf(),
703
+ leaf9 = new Leaf(),
704
+ leaf10 = new Leaf(),
705
+ leaf11 = new Leaf(),
706
+ root = new Node({ children: [leaf1, leaf2, leaf3, leaf4, leaf5, leaf6, leaf7, leaf8, leaf9, leaf10, leaf11] }),
707
+ queueRunner = jasmine.createSpy('queueRunner'),
708
+ processor = new j$.TreeProcessor({
709
+ tree: root,
710
+ runnableIds: [root.id],
711
+ queueRunnerFactory: queueRunner,
712
+ orderChildren: function(node) {
713
+ var children = node.children.slice();
714
+ return children.reverse();
715
+ }
716
+ });
717
+
718
+ processor.execute();
719
+ var queueableFns = queueRunner.calls.mostRecent().args[0].queueableFns;
720
+ expect(queueableFns.length).toBe(11);
721
+
722
+ queueableFns[0].fn();
723
+ expect(leaf11.execute).toHaveBeenCalled();
724
+
725
+ queueableFns[1].fn();
726
+ expect(leaf10.execute).toHaveBeenCalled();
727
+
728
+ queueableFns[2].fn();
729
+ expect(leaf9.execute).toHaveBeenCalled();
730
+
731
+ queueableFns[3].fn();
732
+ expect(leaf8.execute).toHaveBeenCalled();
733
+
734
+ queueableFns[4].fn();
735
+ expect(leaf7.execute).toHaveBeenCalled();
736
+
737
+ queueableFns[5].fn();
738
+ expect(leaf6.execute).toHaveBeenCalled();
739
+
740
+ queueableFns[6].fn();
741
+ expect(leaf5.execute).toHaveBeenCalled();
742
+
743
+ queueableFns[7].fn();
744
+ expect(leaf4.execute).toHaveBeenCalled();
745
+
746
+ queueableFns[8].fn();
747
+ expect(leaf3.execute).toHaveBeenCalled();
748
+
749
+ queueableFns[9].fn();
750
+ expect(leaf2.execute).toHaveBeenCalled();
751
+
752
+ queueableFns[10].fn();
753
+ expect(leaf1.execute).toHaveBeenCalled();
754
+
755
+ });
693
756
  });
@@ -42,4 +42,11 @@ describe("Any", function() {
42
42
  expect(any.jasmineToString()).toEqual('<jasmine.any(Number)>');
43
43
  });
44
44
 
45
+ describe("when called without an argument", function() {
46
+ it("tells the user to pass a constructor or use jasmine.anything()", function() {
47
+ expect(function() {
48
+ new j$.Any();
49
+ }).toThrowError(TypeError, /constructor.*anything/);
50
+ });
51
+ });
45
52
  });
@@ -207,7 +207,6 @@ describe("Env integration", function() {
207
207
  var env = new j$.Env();
208
208
 
209
209
  env.addReporter({jasmineDone: done});
210
-
211
210
  env.describe("tests", function() {
212
211
  var firstTimeThrough = true, firstSpecContext, secondSpecContext;
213
212
 
@@ -1115,6 +1114,78 @@ describe("Env integration", function() {
1115
1114
 
1116
1115
  env.execute();
1117
1116
  });
1117
+
1118
+ it('should run focused tests inside an xdescribe', function(done) {
1119
+ var env = new j$.Env(),
1120
+ reporter = jasmine.createSpyObj('fakeReporter', [
1121
+ "jasmineStarted",
1122
+ "jasmineDone",
1123
+ "suiteStarted",
1124
+ "suiteDone",
1125
+ "specStarted",
1126
+ "specDone"
1127
+ ]);
1128
+
1129
+ reporter.jasmineDone.and.callFake(function() {
1130
+ expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1131
+ totalSpecsDefined: 1
1132
+ });
1133
+
1134
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1135
+ description: 'with a fit spec',
1136
+ status: 'failed'
1137
+ }));
1138
+
1139
+ done();
1140
+ });
1141
+
1142
+ env.addReporter(reporter);
1143
+
1144
+ env.xdescribe("xd suite", function() {
1145
+ env.fit("with a fit spec", function() {
1146
+ env.expect(true).toBe(false);
1147
+ });
1148
+ });
1149
+
1150
+ env.execute();
1151
+ });
1152
+
1153
+ it('should run focused suites inside an xdescribe', function(done) {
1154
+ var env = new j$.Env(),
1155
+ reporter = jasmine.createSpyObj('fakeReporter', [
1156
+ "jasmineStarted",
1157
+ "jasmineDone",
1158
+ "suiteStarted",
1159
+ "suiteDone",
1160
+ "specStarted",
1161
+ "specDone"
1162
+ ]);
1163
+
1164
+ reporter.jasmineDone.and.callFake(function() {
1165
+ expect(reporter.jasmineStarted).toHaveBeenCalledWith({
1166
+ totalSpecsDefined: 1
1167
+ });
1168
+
1169
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({
1170
+ description: 'with a spec',
1171
+ status: 'failed'
1172
+ }));
1173
+
1174
+ done();
1175
+ });
1176
+
1177
+ env.addReporter(reporter);
1178
+
1179
+ env.xdescribe("xd suite", function() {
1180
+ env.fdescribe("fd suite", function() {
1181
+ env.it("with a spec", function() {
1182
+ env.expect(true).toBe(false);
1183
+ });
1184
+ });
1185
+ });
1186
+
1187
+ env.execute();
1188
+ });
1118
1189
  });
1119
1190
 
1120
1191
  it("should report as expected", function(done) {
@@ -1227,9 +1298,10 @@ describe("Env integration", function() {
1227
1298
  totalSpecsDefined: 1
1228
1299
  });
1229
1300
 
1230
- expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'disabled' }));
1231
- expect(reporter.suiteDone.calls.count()).toBe(3);
1232
-
1301
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({ status: 'pending' }));
1302
+ expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({ description: 'xd out', status: 'pending' }));
1303
+ expect(reporter.suiteDone.calls.count()).toBe(4);
1304
+
1233
1305
  done();
1234
1306
  });
1235
1307
 
@@ -1238,8 +1310,10 @@ describe("Env integration", function() {
1238
1310
  env.describe("A Suite", function() {
1239
1311
  env.describe("nested", function() {
1240
1312
  env.xdescribe("xd out", function() {
1241
- env.it("with a spec", function() {
1242
- env.expect(true).toBe(false);
1313
+ env.describe("nested again", function() {
1314
+ env.it("with a spec", function() {
1315
+ env.expect(true).toBe(false);
1316
+ });
1243
1317
  });
1244
1318
  });
1245
1319
  });
@@ -217,10 +217,10 @@ describe("jasmine spec running", function () {
217
217
  "beforeEach1",
218
218
  "beforeEach2",
219
219
  "outer it 1",
220
- "afterEach2",
221
220
  "afterEach1",
222
- "runner afterEach2",
223
- "runner afterEach1"
221
+ "afterEach2",
222
+ "runner afterEach1",
223
+ "runner afterEach2"
224
224
  ];
225
225
  expect(actions).toEqual(expected);
226
226
  done();
@@ -696,4 +696,103 @@ describe("jasmine spec running", function () {
696
696
  env.execute([spec2.id, spec3.id, spec1.id]);
697
697
  }).toThrowError(/afterAll/);
698
698
  });
699
+
700
+ it("should run the tests in a consistent order when a seed is supplied", function(done) {
701
+ var actions = [];
702
+ env.randomizeTests(true);
703
+ env.seed('123456');
704
+
705
+ env.beforeEach(function () {
706
+ actions.push('topSuite beforeEach');
707
+ });
708
+
709
+ env.afterEach(function () {
710
+ actions.push('topSuite afterEach');
711
+ });
712
+
713
+ env.describe('Something', function() {
714
+ env.beforeEach(function() {
715
+ actions.push('outer beforeEach');
716
+ });
717
+
718
+ env.afterEach(function() {
719
+ actions.push('outer afterEach');
720
+ });
721
+
722
+ env.it('does it 1', function() {
723
+ actions.push('outer it 1');
724
+ });
725
+
726
+ env.describe('Inner 1', function() {
727
+ env.beforeEach(function() {
728
+ actions.push('inner 1 beforeEach');
729
+ });
730
+
731
+ env.afterEach(function() {
732
+ actions.push('inner 1 afterEach');
733
+ });
734
+
735
+ env.it('does it 2', function() {
736
+ actions.push('inner 1 it');
737
+ });
738
+ });
739
+
740
+ env.it('does it 3', function() {
741
+ actions.push('outer it 2');
742
+ });
743
+
744
+ env.describe('Inner 2', function() {
745
+ env.beforeEach(function() {
746
+ actions.push('inner 2 beforeEach');
747
+ });
748
+
749
+ env.afterEach(function() {
750
+ actions.push('inner 2 afterEach');
751
+ });
752
+
753
+ env.it('does it 2', function() {
754
+ actions.push('inner 2 it');
755
+ });
756
+ });
757
+ });
758
+
759
+ var assertions = function() {
760
+ var expected = [
761
+ 'topSuite beforeEach',
762
+ 'outer beforeEach',
763
+ 'outer it 2',
764
+ 'outer afterEach',
765
+ 'topSuite afterEach',
766
+
767
+ 'topSuite beforeEach',
768
+ 'outer beforeEach',
769
+ 'inner 2 beforeEach',
770
+ 'inner 2 it',
771
+ 'inner 2 afterEach',
772
+ 'outer afterEach',
773
+ 'topSuite afterEach',
774
+
775
+ 'topSuite beforeEach',
776
+ 'outer beforeEach',
777
+ 'inner 1 beforeEach',
778
+ 'inner 1 it',
779
+ 'inner 1 afterEach',
780
+ 'outer afterEach',
781
+ 'topSuite afterEach',
782
+
783
+ 'topSuite beforeEach',
784
+ 'outer beforeEach',
785
+ 'outer it 1',
786
+ 'outer afterEach',
787
+ 'topSuite afterEach'
788
+ ];
789
+ expect(actions).toEqual(expected);
790
+ done();
791
+ };
792
+
793
+ env.addReporter({jasmineDone: assertions});
794
+
795
+ env.execute();
796
+ });
797
+
699
798
  });
@@ -0,0 +1,81 @@
1
+ describe("toHaveBeenCalledTimes", function() {
2
+ it("passes when the actual matches the expected", function() {
3
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
4
+ calledSpy = j$.createSpy('called-spy'),
5
+ result;
6
+ calledSpy();
7
+
8
+ result = matcher.compare(calledSpy, 1);
9
+ expect(result.pass).toBe(true);
10
+ });
11
+
12
+ it("fails when expected numbers is not supplied", function(){
13
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
14
+ spy = j$.createSpy('spy'),
15
+ result;
16
+
17
+ spy();
18
+ expect(function() {
19
+ matcher.compare(spy);
20
+ }).toThrowError('Expected times failed is required as an argument.');
21
+ });
22
+
23
+ it("fails when the actual was called less than the expected", function() {
24
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
25
+ uncalledSpy = j$.createSpy('uncalled spy'),
26
+ result;
27
+
28
+ result = matcher.compare(uncalledSpy, 2);
29
+ expect(result.pass).toBe(false);
30
+ });
31
+
32
+ it("fails when the actual was called more than expected", function() {
33
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
34
+ uncalledSpy = j$.createSpy('uncalled spy'),
35
+ result;
36
+
37
+ uncalledSpy();
38
+ uncalledSpy();
39
+
40
+ result = matcher.compare(uncalledSpy, 1);
41
+ expect(result.pass).toBe(false);
42
+ });
43
+
44
+ it("throws an exception when the actual is not a spy", function() {
45
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
46
+ fn = function() {};
47
+
48
+ expect(function() {
49
+ matcher.compare(fn);
50
+ }).toThrowError("Expected a spy, but got Function.");
51
+ });
52
+
53
+ it("has a custom message on failure that tells it was called only once", function() {
54
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
55
+ spy = j$.createSpy('sample-spy'),
56
+ result;
57
+ spy();
58
+ spy();
59
+ spy();
60
+ spy();
61
+
62
+ result = matcher.compare(spy, 1);
63
+
64
+ expect(result.message).toEqual('Expected spy sample-spy to have been called once. It was called ' + 4 + ' times.');
65
+ });
66
+
67
+ it("has a custom message on failure that tells how many times it was called", function() {
68
+ var matcher = j$.matchers.toHaveBeenCalledTimes(),
69
+ spy = j$.createSpy('sample-spy'),
70
+ result;
71
+ spy();
72
+ spy();
73
+ spy();
74
+ spy();
75
+
76
+ result = matcher.compare(spy, 2);
77
+
78
+ expect(result.message).toEqual('Expected spy sample-spy to have been called 2 times. It was called ' + 4 + ' times.');
79
+ });
80
+ });
81
+