jasmine-core 2.0.0.rc5 → 2.0.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.
@@ -13,20 +13,20 @@ describe('Exceptions:', function() {
13
13
  throw new Error('I should hit a breakpoint!');
14
14
  });
15
15
  });
16
- var dont_change = 'I will never change!';
16
+ var spy = jasmine.createSpy('spy');
17
17
 
18
18
  try {
19
19
  env.execute();
20
- dont_change = 'oops I changed';
20
+ spy();
21
21
  }
22
22
  catch (e) {}
23
23
 
24
- expect(dont_change).toEqual('I will never change!');
24
+ expect(spy).not.toHaveBeenCalled();
25
25
  });
26
26
  });
27
27
 
28
28
  describe("with catch on exception", function() {
29
- it('should handle exceptions thrown, but continue', function() {
29
+ it('should handle exceptions thrown, but continue', function(done) {
30
30
  var secondTest = jasmine.createSpy('second test');
31
31
  env.describe('Suite for handles exceptions', function () {
32
32
  env.it('should be a test that fails because it throws an exception', function() {
@@ -35,11 +35,16 @@ describe('Exceptions:', function() {
35
35
  env.it('should be a passing test that runs after exceptions are thrown from a async test', secondTest);
36
36
  });
37
37
 
38
+ expectations = function() {
39
+ expect(secondTest).toHaveBeenCalled();
40
+ done();
41
+ };
42
+
43
+ env.addReporter({ jasmineDone: expectations });
38
44
  env.execute();
39
- expect(secondTest).toHaveBeenCalled();
40
45
  });
41
46
 
42
- it("should handle exceptions thrown directly in top-level describe blocks and continue", function () {
47
+ it("should handle exceptions thrown directly in top-level describe blocks and continue", function(done) {
43
48
  var secondDescribe = jasmine.createSpy("second describe");
44
49
  env.describe("a suite that throws an exception", function () {
45
50
  env.it("is a test that should pass", function () {
@@ -50,8 +55,13 @@ describe('Exceptions:', function() {
50
55
  });
51
56
  env.describe("a suite that doesn't throw an exception", secondDescribe);
52
57
 
58
+ expectations = function() {
59
+ expect(secondDescribe).toHaveBeenCalled();
60
+ done();
61
+ };
62
+
63
+ env.addReporter({ jasmineDone: expectations });
53
64
  env.execute();
54
- expect(secondDescribe).toHaveBeenCalled();
55
65
  });
56
66
  });
57
67
  });
@@ -9,7 +9,7 @@ describe("buildExpectationResult", function() {
9
9
  expect(result.message).toBe('Passed.');
10
10
  });
11
11
 
12
- it("message returns the message for failing expecations", function() {
12
+ it("message returns the message for failing expectations", function() {
13
13
  var result = j$.buildExpectationResult({passed: false, message: 'some-value'});
14
14
  expect(result.message).toBe('some-value');
15
15
  });
@@ -46,7 +46,7 @@ describe("Expectation", function() {
46
46
  expect(expectation.toFoo).toBeUndefined();
47
47
  });
48
48
 
49
- it("Factory builds an expectaion/negative expectation", function() {
49
+ it("Factory builds an expectation/negative expectation", function() {
50
50
  var builtExpectation = j$.Expectation.Factory();
51
51
 
52
52
  expect(builtExpectation instanceof j$.Expectation).toBe(true);
@@ -254,7 +254,7 @@ describe("Expectation", function() {
254
254
  }
255
255
  },
256
256
  util = {
257
- buildFailureMessage: function() { return "default messge"; }
257
+ buildFailureMessage: function() { return "default message"; }
258
258
  },
259
259
  addExpectationResult = jasmine.createSpy("addExpectationResult"),
260
260
  actual = "an actual",
@@ -277,7 +277,7 @@ describe("Expectation", function() {
277
277
  passed: false,
278
278
  expected: "hello",
279
279
  actual: actual,
280
- message: "default messge"
280
+ message: "default message"
281
281
  });
282
282
  });
283
283
 
@@ -26,7 +26,7 @@ describe("Spec", function() {
26
26
  description: 'my test',
27
27
  id: 'some-id',
28
28
  fn: function() {},
29
- queueRunner: fakeQueueRunner
29
+ queueRunnerFactory: fakeQueueRunner
30
30
  });
31
31
 
32
32
  spec.execute();
@@ -42,7 +42,7 @@ describe("Spec", function() {
42
42
  description: 'foo bar',
43
43
  fn: function() {},
44
44
  onStart: startCallback,
45
- queueRunner: fakeQueueRunner
45
+ queueRunnerFactory: fakeQueueRunner
46
46
  });
47
47
 
48
48
  spec.execute();
@@ -69,7 +69,7 @@ describe("Spec", function() {
69
69
  }]
70
70
  },
71
71
  onStart: startCallback,
72
- queueRunner: fakeQueueRunner
72
+ queueRunnerFactory: fakeQueueRunner
73
73
  });
74
74
 
75
75
  spec.execute();
@@ -93,7 +93,7 @@ describe("Spec", function() {
93
93
  afterFns: function() {
94
94
  return [after]
95
95
  },
96
- queueRunner: fakeQueueRunner
96
+ queueRunnerFactory: fakeQueueRunner
97
97
  });
98
98
 
99
99
  spec.execute();
@@ -111,7 +111,7 @@ describe("Spec", function() {
111
111
  onStart: startCallback,
112
112
  fn: null,
113
113
  resultCallback: resultCallback,
114
- queueRunner: fakeQueueRunner
114
+ queueRunnerFactory: fakeQueueRunner
115
115
  });
116
116
 
117
117
 
@@ -127,7 +127,7 @@ describe("Spec", function() {
127
127
  onStart:startCallback,
128
128
  fn: specBody,
129
129
  resultCallback: resultCallback,
130
- queueRunner: fakeQueueRunner
130
+ queueRunnerFactory: fakeQueueRunner
131
131
  });
132
132
 
133
133
  spec.disable();
@@ -154,7 +154,7 @@ describe("Spec", function() {
154
154
  getSpecName: function() {
155
155
  return "a suite with a spec"
156
156
  },
157
- queueRunner: fakeQueueRunner
157
+ queueRunnerFactory: fakeQueueRunner
158
158
  });
159
159
 
160
160
  spec.pend();
@@ -181,7 +181,7 @@ describe("Spec", function() {
181
181
  fn: function() {},
182
182
  catchExceptions: function() { return false; },
183
183
  resultCallback: function() {},
184
- queueRunner: function(attrs) { attrs.onComplete(); }
184
+ queueRunnerFactory: function(attrs) { attrs.onComplete(); }
185
185
  });
186
186
 
187
187
  spec.execute(done);
@@ -208,17 +208,99 @@ describe("Spec", function() {
208
208
  });
209
209
 
210
210
  it("can return its full name", function() {
211
- var spec;
212
- spec = new j$.Spec({
213
- getSpecName: function(passedVal) {
214
- // expect(passedVal).toBe(spec); TODO: a exec time, spec is undefined WTF?
215
- return 'expected val';
216
- }
211
+ var specNameSpy = jasmine.createSpy('specNameSpy').and.returnValue('expected val');
212
+
213
+ var spec = new j$.Spec({
214
+ getSpecName: specNameSpy
217
215
  });
218
216
 
219
217
  expect(spec.getFullName()).toBe('expected val');
218
+ expect(specNameSpy.calls.mostRecent().args[0].id).toEqual(spec.id);
220
219
  });
221
220
 
221
+ it("sets a timeout for async functions to keep them from running forever", function() {
222
+ var queueRunnerSpy = jasmine.createSpy('queue runner'),
223
+ setTimeoutSpy = jasmine.createSpy('setTimeout'),
224
+ spec = new j$.Spec({
225
+ beforeFns: function() { return [function(done) { }]; },
226
+ fn: function(done) { },
227
+ afterFns: function() { return [function(done) { }]; },
228
+ timer: {
229
+ setTimeout: setTimeoutSpy,
230
+ clearTimeout: function() {}
231
+ },
232
+ queueRunnerFactory: queueRunnerSpy
233
+ });
234
+
235
+ spec.execute();
236
+ var fns = queueRunnerSpy.calls.mostRecent().args[0].fns;
237
+
238
+ for (var i = 0; i < fns.length; i++) {
239
+ fns[i]();
240
+ }
241
+
242
+ expect(setTimeoutSpy.calls.count()).toEqual(3);
243
+ expect(setTimeoutSpy).toHaveBeenCalledWith(jasmine.any(Function), j$.DEFAULT_TIMEOUT_INTERVAL);
244
+ });
245
+
246
+ it("resets the timeout timer when an async before throws an exception", function() {
247
+ var queueRunnerSpy = jasmine.createSpy('queueRunner'),
248
+ clearTimeoutSpy = jasmine.createSpy('clear timeout'),
249
+ spec = new j$.Spec({
250
+ beforeFns: function() { return [function(done) {}]; },
251
+ fn: function() { },
252
+ timer: {
253
+ setTimeout: function () { return 920; },
254
+ clearTimeout: clearTimeoutSpy
255
+ },
256
+ queueRunnerFactory: queueRunnerSpy
257
+ });
258
+
259
+ spec.execute();
260
+ queueRunnerSpy.calls.mostRecent().args[0].fns[0]();
261
+ queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
262
+
263
+ expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
264
+ });
265
+
266
+ it("resets the timeout timer when an async spec throws an exception", function() {
267
+ var queueRunnerSpy = jasmine.createSpy('queueRunner'),
268
+ clearTimeoutSpy = jasmine.createSpy('clear timeout'),
269
+ spec = new j$.Spec({
270
+ fn: function(done) { },
271
+ timer: {
272
+ setTimeout: function () { return 920; },
273
+ clearTimeout: clearTimeoutSpy
274
+ },
275
+ queueRunnerFactory: queueRunnerSpy
276
+ });
277
+
278
+ spec.execute();
279
+ queueRunnerSpy.calls.mostRecent().args[0].fns[0]();
280
+ queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
281
+
282
+ expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
283
+ });
284
+
285
+ it("resets the timeout timer when an async after spec throws an exception", function() {
286
+ var queueRunnerSpy = jasmine.createSpy('queueRunner'),
287
+ clearTimeoutSpy = jasmine.createSpy('clear timeout'),
288
+ spec = new j$.Spec({
289
+ fn: function() { },
290
+ afterFns: function() { return [function(done) {}]; },
291
+ timer: {
292
+ setTimeout: function () { return 920; },
293
+ clearTimeout: clearTimeoutSpy
294
+ },
295
+ queueRunnerFactory: queueRunnerSpy
296
+ });
297
+
298
+ spec.execute();
299
+ queueRunnerSpy.calls.mostRecent().args[0].fns[1]();
300
+ queueRunnerSpy.calls.mostRecent().args[0].onException(new Error());
301
+
302
+ expect(clearTimeoutSpy).toHaveBeenCalledWith(920);
303
+ });
222
304
  describe("when a spec is marked pending during execution", function() {
223
305
  it("should mark the spec as pending", function() {
224
306
  var fakeQueueRunner = function(opts) {
@@ -228,7 +310,7 @@ describe("Spec", function() {
228
310
  description: 'my test',
229
311
  id: 'some-id',
230
312
  fn: function() { },
231
- queueRunner: fakeQueueRunner
313
+ queueRunnerFactory: fakeQueueRunner
232
314
  });
233
315
 
234
316
  spec.execute();
@@ -14,7 +14,7 @@ describe('Spies', function () {
14
14
  expect(spy.bob).toEqual("test");
15
15
  });
16
16
 
17
- it("warns the user that we indend to overwrite an existing property", function() {
17
+ it("warns the user that we intend to overwrite an existing property", function() {
18
18
  TestClass.prototype.someFunction.and = "turkey";
19
19
 
20
20
  expect(function() {
@@ -28,6 +28,25 @@ describe('Spies', function () {
28
28
  expect(spy.and).toEqual(jasmine.any(j$.SpyStrategy));
29
29
  expect(spy.calls).toEqual(jasmine.any(j$.CallTracker));
30
30
  });
31
+
32
+ it("tracks the argument of calls", function () {
33
+ var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
34
+ var trackSpy = spyOn(spy.calls, "track");
35
+
36
+ spy("arg");
37
+
38
+ expect(trackSpy.calls.mostRecent().args[0].args).toEqual(["arg"]);
39
+ });
40
+
41
+ it("tracks the context of calls", function () {
42
+ var spy = j$.createSpy(TestClass.prototype, TestClass.prototype.someFunction);
43
+ var trackSpy = spyOn(spy.calls, "track");
44
+
45
+ var contextObject = { spyMethod: spy };
46
+ contextObject.spyMethod();
47
+
48
+ expect(trackSpy.calls.mostRecent().args[0].object).toEqual(contextObject);
49
+ });
31
50
  });
32
51
 
33
52
  describe("createSpyObj", function() {
@@ -0,0 +1,488 @@
1
+ describe("Env integration", function() {
2
+
3
+ it("Suites execute as expected (no nesting)", function(done) {
4
+ var env = new j$.Env(),
5
+ calls = [];
6
+
7
+ var assertions = function() {
8
+ expect(calls).toEqual([
9
+ "with a spec",
10
+ "and another spec"
11
+ ]);
12
+
13
+ done();
14
+ };
15
+
16
+ env.addReporter({ jasmineDone: assertions});
17
+
18
+ env.describe("A Suite", function() {
19
+ env.it("with a spec", function() {
20
+ calls.push("with a spec");
21
+ });
22
+ env.it("and another spec", function() {
23
+ calls.push("and another spec");
24
+ });
25
+ });
26
+
27
+ env.execute();
28
+ });
29
+
30
+ it("Nested Suites execute as expected", function(done) {
31
+ var env = new j$.Env(),
32
+ calls = [];
33
+
34
+ var assertions = function() {
35
+ expect(calls).toEqual([
36
+ 'an outer spec',
37
+ 'an inner spec',
38
+ 'another inner spec'
39
+ ]);
40
+
41
+ done();
42
+ };
43
+
44
+ env.addReporter({ jasmineDone: assertions });
45
+
46
+ env.describe("Outer suite", function() {
47
+ env.it("an outer spec", function() {
48
+ calls.push('an outer spec')
49
+ });
50
+ env.describe("Inner suite", function() {
51
+ env.it("an inner spec", function() {
52
+ calls.push('an inner spec');
53
+ });
54
+ env.it("another inner spec", function() {
55
+ calls.push('another inner spec');
56
+ });
57
+ });
58
+ });
59
+
60
+ env.execute();
61
+ });
62
+
63
+ it("Multiple top-level Suites execute as expected", function(done) {
64
+ var env = new j$.Env(),
65
+ calls = [];
66
+
67
+ var assertions = function() {
68
+ expect(calls).toEqual([
69
+ 'an outer spec',
70
+ 'an inner spec',
71
+ 'another inner spec',
72
+ 'a 2nd outer spec'
73
+ ]);
74
+
75
+ done();
76
+ };
77
+
78
+ env.addReporter({ jasmineDone: assertions });
79
+
80
+
81
+ env.describe("Outer suite", function() {
82
+ env.it("an outer spec", function() {
83
+ calls.push('an outer spec')
84
+ });
85
+ env.describe("Inner suite", function() {
86
+ env.it("an inner spec", function() {
87
+ calls.push('an inner spec');
88
+ });
89
+ env.it("another inner spec", function() {
90
+ calls.push('another inner spec');
91
+ });
92
+ });
93
+ });
94
+
95
+ env.describe("Another outer suite", function() {
96
+ env.it("a 2nd outer spec", function() {
97
+ calls.push('a 2nd outer spec')
98
+ });
99
+ });
100
+
101
+ env.execute();
102
+ });
103
+
104
+ it("calls associated befores/specs/afters with the same 'this'", function(done) {
105
+ var env = new j$.Env();
106
+
107
+ env.addReporter({jasmineDone: done});
108
+
109
+ env.describe("tests", function() {
110
+ var firstTimeThrough = true, firstSpecContext, secondSpecContext;
111
+
112
+ env.beforeEach(function() {
113
+ if (firstTimeThrough) {
114
+ firstSpecContext = this;
115
+ } else {
116
+ secondSpecContext = this;
117
+ }
118
+ expect(this).toEqual({});
119
+ });
120
+
121
+ env.it("sync spec", function() {
122
+ expect(this).toBe(firstSpecContext);
123
+ });
124
+
125
+ env.it("another sync spec", function() {
126
+ expect(this).toBe(secondSpecContext);
127
+ });
128
+
129
+ env.afterEach(function() {
130
+ if (firstTimeThrough) {
131
+ expect(this).toBe(firstSpecContext);
132
+ firstTimeThrough = false;
133
+ } else {
134
+ expect(this).toBe(secondSpecContext);
135
+ }
136
+ });
137
+ });
138
+
139
+ env.execute();
140
+ });
141
+
142
+ it("calls associated befores/its/afters with the same 'this' for an async spec", function(done) {
143
+ var env = new j$.Env();
144
+
145
+ env.addReporter({jasmineDone: done});
146
+
147
+ env.describe("with an async spec", function() {
148
+ var specContext;
149
+
150
+ env.beforeEach(function() {
151
+ specContext = this;
152
+ expect(this).toEqual({});
153
+ });
154
+
155
+ env.it("sync spec", function(underTestCallback) {
156
+ expect(this).toBe(specContext);
157
+ underTestCallback();
158
+ });
159
+
160
+ env.afterEach(function() {
161
+ expect(this).toBe(specContext);
162
+ });
163
+ });
164
+
165
+ env.execute();
166
+ });
167
+
168
+ it("Allows specifying which specs and suites to run", function(done) {
169
+ var env = new j$.Env(),
170
+ calls = [],
171
+ suiteCallback = jasmine.createSpy('suite callback'),
172
+ firstSpec,
173
+ secondSuite;
174
+
175
+ var assertions = function() {
176
+ expect(calls).toEqual([
177
+ 'third spec',
178
+ 'first spec'
179
+ ]);
180
+ expect(suiteCallback).toHaveBeenCalled();
181
+ done();
182
+ };
183
+
184
+ env.addReporter({jasmineDone: assertions, suiteDone: suiteCallback});
185
+
186
+ env.describe("first suite", function() {
187
+ firstSpec = env.it("first spec", function() {
188
+ calls.push('first spec');
189
+ });
190
+ env.it("second spec", function() {
191
+ calls.push('second spec');
192
+ });
193
+ });
194
+
195
+ secondSuite = env.describe("second suite", function() {
196
+ env.it("third spec", function() {
197
+ calls.push('third spec');
198
+ });
199
+ });
200
+
201
+ env.execute([secondSuite.id, firstSpec.id]);
202
+ });
203
+
204
+ it("Functions can be spied on and have their calls tracked", function () {
205
+ var env = new j$.Env();
206
+
207
+ var originalFunctionWasCalled = false;
208
+ var subject = { spiedFunc: function() { originalFunctionWasCalled = true; } };
209
+
210
+ var spy = env.spyOn(subject, 'spiedFunc');
211
+
212
+ expect(subject.spiedFunc).toEqual(spy);
213
+
214
+ expect(subject.spiedFunc.calls.any()).toEqual(false);
215
+ expect(subject.spiedFunc.calls.count()).toEqual(0);
216
+
217
+ subject.spiedFunc('foo');
218
+
219
+ expect(subject.spiedFunc.calls.any()).toEqual(true);
220
+ expect(subject.spiedFunc.calls.count()).toEqual(1);
221
+ expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['foo']);
222
+ expect(subject.spiedFunc.calls.mostRecent().object).toEqual(subject);
223
+ expect(originalFunctionWasCalled).toEqual(false);
224
+
225
+ subject.spiedFunc('bar');
226
+ expect(subject.spiedFunc.calls.count()).toEqual(2);
227
+ expect(subject.spiedFunc.calls.mostRecent().args).toEqual(['bar']);
228
+ });
229
+
230
+ it("Mock clock can be installed and used in tests", function(done) {
231
+ var globalSetTimeout = jasmine.createSpy('globalSetTimeout'),
232
+ delayedFunctionForGlobalClock = jasmine.createSpy('delayedFunctionForGlobalClock'),
233
+ delayedFunctionForMockClock = jasmine.createSpy('delayedFunctionForMockClock'),
234
+ env = new j$.Env({global: { setTimeout: globalSetTimeout }});
235
+
236
+ var assertions = function() {
237
+ expect(delayedFunctionForMockClock).toHaveBeenCalled();
238
+ expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100);
239
+
240
+ done();
241
+ };
242
+
243
+ env.addReporter({ jasmineDone: assertions });
244
+
245
+ env.describe("tests", function() {
246
+ env.it("test with mock clock", function() {
247
+ env.clock.install();
248
+ env.clock.setTimeout(delayedFunctionForMockClock, 100);
249
+ env.clock.tick(100);
250
+ env.clock.uninstall();
251
+ });
252
+ env.it("test without mock clock", function() {
253
+ env.clock.setTimeout(delayedFunctionForGlobalClock, 100);
254
+ });
255
+ });
256
+
257
+ expect(globalSetTimeout).not.toHaveBeenCalled();
258
+ expect(delayedFunctionForMockClock).not.toHaveBeenCalled();
259
+
260
+ env.execute();
261
+ });
262
+
263
+ it("should run async specs in order, waiting for them to complete", function(done) {
264
+ var env = new j$.Env(), mutatedVar;
265
+
266
+ env.describe("tests", function() {
267
+ env.beforeEach(function() {
268
+ mutatedVar = 2;
269
+ });
270
+
271
+ env.it("async spec", function(underTestCallback) {
272
+ setTimeout(function() {
273
+ expect(mutatedVar).toEqual(2);
274
+ underTestCallback();
275
+ done();
276
+ }, 0);
277
+ });
278
+
279
+ env.it("after async spec", function() {
280
+ mutatedVar = 3;
281
+ });
282
+ });
283
+
284
+ env.execute();
285
+ });
286
+
287
+ describe("with a mock clock", function() {
288
+ var originalTimeout;
289
+
290
+ beforeEach(function() {
291
+ originalTimeout = j$.DEFAULT_TIMEOUT_INTERVAL;
292
+ jasmine.getEnv().clock.install();
293
+ });
294
+
295
+ afterEach(function() {
296
+ jasmine.getEnv().clock.uninstall();
297
+ j$.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
298
+ });
299
+
300
+ it("should wait a specified interval before failing specs haven't called done yet", function(done) {
301
+ var env = new j$.Env(),
302
+ reporter = jasmine.createSpyObj('fakeReporter', [ "specDone" ]);
303
+
304
+ reporter.specDone.and.callFake(function() {
305
+ expect(reporter.specDone).toHaveBeenCalledWith(jasmine.objectContaining({status: 'failed'}));
306
+ done();
307
+ });
308
+
309
+ env.addReporter(reporter);
310
+ j$.DEFAULT_TIMEOUT_INTERVAL = 8414;
311
+
312
+ env.it("async spec that doesn't call done", function(underTestCallback) {
313
+ env.expect(true).toBeTruthy();
314
+ jasmine.getEnv().clock.tick(8415);
315
+ });
316
+
317
+ env.execute();
318
+ });
319
+ });
320
+
321
+ // TODO: something is wrong with this spec
322
+ it("should report as expected", function(done) {
323
+ var env = new j$.Env(),
324
+ reporter = jasmine.createSpyObj('fakeReporter', [
325
+ "jasmineStarted",
326
+ "jasmineDone",
327
+ "suiteStarted",
328
+ "suiteDone",
329
+ "specStarted",
330
+ "specDone"
331
+ ]);
332
+
333
+ reporter.jasmineDone.and.callFake(function() {
334
+ expect(reporter.jasmineStarted).toHaveBeenCalledWith({
335
+ totalSpecsDefined: 3
336
+ });
337
+ var suiteResult = reporter.suiteStarted.calls.first().args[0];
338
+ expect(suiteResult.description).toEqual("A Suite");
339
+
340
+ done();
341
+ });
342
+
343
+ env.addReporter(reporter);
344
+
345
+ env.describe("A Suite", function() {
346
+ env.it("with a top level spec", function() {
347
+ env.expect(true).toBe(true);
348
+ });
349
+ env.describe("with a nested suite", function() {
350
+ env.xit("with a pending spec", function() {
351
+ env.expect(true).toBe(true);
352
+ });
353
+ env.it("with a spec", function() {
354
+ env.expect(true).toBe(false);
355
+ });
356
+ });
357
+ });
358
+
359
+ env.execute();
360
+ });
361
+
362
+ it("should be possible to get full name from a spec", function() {
363
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
364
+ topLevelSpec, nestedSpec, doublyNestedSpec;
365
+
366
+ env.describe("my tests", function() {
367
+ topLevelSpec = env.it("are sometimes top level", function() {
368
+ });
369
+ env.describe("are sometimes", function() {
370
+ nestedSpec = env.it("singly nested", function() {
371
+ });
372
+ env.describe("even", function() {
373
+ doublyNestedSpec = env.it("doubly nested", function() {
374
+ });
375
+ });
376
+ });
377
+ });
378
+
379
+ expect(topLevelSpec.getFullName()).toBe("my tests are sometimes top level");
380
+ expect(nestedSpec.getFullName()).toBe("my tests are sometimes singly nested");
381
+ expect(doublyNestedSpec.getFullName()).toBe("my tests are sometimes even doubly nested");
382
+ });
383
+
384
+ it("Custom equality testers should be per spec", function(done) {
385
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
386
+ reporter = jasmine.createSpyObj('fakeReporter', [
387
+ "jasmineStarted",
388
+ "jasmineDone",
389
+ "suiteStarted",
390
+ "suiteDone",
391
+ "specStarted",
392
+ "specDone"
393
+ ]);
394
+
395
+ reporter.jasmineDone.and.callFake(function() {
396
+ var firstSpecResult = reporter.specDone.calls.first().args[0],
397
+ secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
398
+
399
+ expect(firstSpecResult.status).toEqual("passed");
400
+ expect(secondSpecResult.status).toEqual("failed");
401
+
402
+ done();
403
+ });
404
+
405
+ env.addReporter(reporter);
406
+
407
+ env.describe("testing custom equality testers", function() {
408
+ env.it("with a custom tester", function() {
409
+ env.addCustomEqualityTester(function(a, b) { return true; });
410
+ env.expect("a").toEqual("b");
411
+ });
412
+
413
+ env.it("without a custom tester", function() {
414
+ env.expect("a").toEqual("b");
415
+ });
416
+ });
417
+
418
+ env.execute();
419
+ });
420
+
421
+ it("Custom matchers should be per spec", function() {
422
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
423
+ matchers = {
424
+ toFoo: function() {}
425
+ },
426
+ reporter = jasmine.createSpyObj('fakeReporter', [
427
+ "jasmineStarted",
428
+ "jasmineDone",
429
+ "suiteStarted",
430
+ "suiteDone",
431
+ "specStarted",
432
+ "specDone"
433
+ ]);
434
+
435
+ env.addReporter(reporter);
436
+
437
+ env.describe("testing custom matchers", function() {
438
+ env.it("with a custom matcher", function() {
439
+ env.addMatchers(matchers);
440
+ expect(env.expect().toFoo).toBeDefined();
441
+ });
442
+
443
+ env.it("without a custom matcher", function() {
444
+ expect(env.expect().toFoo).toBeUndefined();
445
+ });
446
+ });
447
+
448
+ env.execute();
449
+ });
450
+
451
+ it("Custom equality testers for toContain should be per spec", function(done) {
452
+ var env = new j$.Env({global: { setTimeout: setTimeout }}),
453
+ reporter = jasmine.createSpyObj('fakeReporter', [
454
+ "jasmineStarted",
455
+ "jasmineDone",
456
+ "suiteStarted",
457
+ "suiteDone",
458
+ "specStarted",
459
+ "specDone"
460
+ ]);
461
+
462
+ reporter.jasmineDone.and.callFake(function() {
463
+ var firstSpecResult = reporter.specDone.calls.first().args[0],
464
+ secondSpecResult = reporter.specDone.calls.mostRecent().args[0];
465
+
466
+ expect(firstSpecResult.status).toEqual("passed");
467
+ expect(secondSpecResult.status).toEqual("failed");
468
+
469
+ done();
470
+ });
471
+
472
+ env.addReporter(reporter);
473
+
474
+ env.describe("testing custom equality testers", function() {
475
+ env.it("with a custom tester", function() {
476
+ env.addCustomEqualityTester(function(a, b) { return true; });
477
+ env.expect(["a"]).toContain("b");
478
+ });
479
+
480
+ env.it("without a custom tester", function() {
481
+ env.expect("a").toContain("b");
482
+ });
483
+ });
484
+
485
+ env.execute();
486
+ });
487
+ });
488
+