js-test-driver-rails 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.gitmodules +6 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +8 -9
- data/Rakefile +3 -28
- data/js-test-driver-rails.gemspec +25 -0
- data/lib/js_test_driver/version.rb +3 -0
- metadata +17 -183
- data/VERSION +0 -1
- data/vendor/jasmine-jstd-adapter/MIT.LICENSE +0 -22
- data/vendor/jasmine-jstd-adapter/README.md +0 -25
- data/vendor/jasmine-jstd-adapter/jsTestDriver.conf +0 -6
- data/vendor/jasmine-jstd-adapter/jsTestDriverIit.conf +0 -6
- data/vendor/jasmine-jstd-adapter/lib/jasmine/jasmine-0.11.1.js +0 -2343
- data/vendor/jasmine-jstd-adapter/lib/jstestdriver/JsTestDriver.jar +0 -0
- data/vendor/jasmine-jstd-adapter/server.sh +0 -1
- data/vendor/jasmine-jstd-adapter/src-test/iit/iitSpec.js +0 -46
- data/vendor/jasmine-jstd-adapter/src-test/tests.js +0 -89
- data/vendor/jasmine-jstd-adapter/src/JasmineAdapter.js +0 -186
- data/vendor/jasmine-jstd-adapter/test-iit.sh +0 -1
- data/vendor/jasmine-jstd-adapter/test-regular.sh +0 -2
- data/vendor/jasmine-jstd-adapter/test.sh +0 -2
- data/vendor/jasmine/Gemfile +0 -6
- data/vendor/jasmine/MIT.LICENSE +0 -20
- data/vendor/jasmine/README.markdown +0 -28
- data/vendor/jasmine/Rakefile +0 -182
- data/vendor/jasmine/cruise_config.rb +0 -21
- data/vendor/jasmine/example/SpecRunner.html +0 -27
- data/vendor/jasmine/example/spec/PlayerSpec.js +0 -58
- data/vendor/jasmine/example/spec/SpecHelper.js +0 -9
- data/vendor/jasmine/example/src/Player.js +0 -22
- data/vendor/jasmine/example/src/Song.js +0 -7
- data/vendor/jasmine/images/fail-16.png +0 -0
- data/vendor/jasmine/images/fail.png +0 -0
- data/vendor/jasmine/images/go-16.png +0 -0
- data/vendor/jasmine/images/go.png +0 -0
- data/vendor/jasmine/images/pending-16.png +0 -0
- data/vendor/jasmine/images/pending.png +0 -0
- data/vendor/jasmine/images/question-bk.png +0 -0
- data/vendor/jasmine/images/questionbk-16.png +0 -0
- data/vendor/jasmine/images/spinner.gif +0 -0
- data/vendor/jasmine/jsdoc-template/allclasses.tmpl +0 -17
- data/vendor/jasmine/jsdoc-template/allfiles.tmpl +0 -56
- data/vendor/jasmine/jsdoc-template/class.tmpl +0 -646
- data/vendor/jasmine/jsdoc-template/index.tmpl +0 -39
- data/vendor/jasmine/jsdoc-template/publish.js +0 -184
- data/vendor/jasmine/jsdoc-template/static/default.css +0 -162
- data/vendor/jasmine/jsdoc-template/static/header.html +0 -2
- data/vendor/jasmine/jsdoc-template/static/index.html +0 -19
- data/vendor/jasmine/jsdoc-template/symbol.tmpl +0 -35
- data/vendor/jasmine/lib/jasmine-html.js +0 -188
- data/vendor/jasmine/lib/jasmine.css +0 -166
- data/vendor/jasmine/lib/jasmine.js +0 -2421
- data/vendor/jasmine/lib/json2.js +0 -478
- data/vendor/jasmine/spec/runner.html +0 -80
- data/vendor/jasmine/spec/suites/BaseSpec.js +0 -27
- data/vendor/jasmine/spec/suites/CustomMatchersSpec.js +0 -97
- data/vendor/jasmine/spec/suites/EnvSpec.js +0 -158
- data/vendor/jasmine/spec/suites/ExceptionsSpec.js +0 -107
- data/vendor/jasmine/spec/suites/JsApiReporterSpec.js +0 -103
- data/vendor/jasmine/spec/suites/MatchersSpec.js +0 -795
- data/vendor/jasmine/spec/suites/MockClockSpec.js +0 -38
- data/vendor/jasmine/spec/suites/MultiReporterSpec.js +0 -45
- data/vendor/jasmine/spec/suites/NestedResultsSpec.js +0 -54
- data/vendor/jasmine/spec/suites/PrettyPrintSpec.js +0 -93
- data/vendor/jasmine/spec/suites/QueueSpec.js +0 -23
- data/vendor/jasmine/spec/suites/ReporterSpec.js +0 -56
- data/vendor/jasmine/spec/suites/RunnerSpec.js +0 -267
- data/vendor/jasmine/spec/suites/SpecRunningSpec.js +0 -1253
- data/vendor/jasmine/spec/suites/SpecSpec.js +0 -124
- data/vendor/jasmine/spec/suites/SpySpec.js +0 -201
- data/vendor/jasmine/spec/suites/SuiteSpec.js +0 -120
- data/vendor/jasmine/spec/suites/TrivialReporterSpec.js +0 -238
- data/vendor/jasmine/spec/suites/UtilSpec.js +0 -40
- data/vendor/jasmine/spec/suites/WaitsForBlockSpec.js +0 -87
- data/vendor/jasmine/src/Block.js +0 -22
- data/vendor/jasmine/src/Env.js +0 -264
- data/vendor/jasmine/src/JsApiReporter.js +0 -102
- data/vendor/jasmine/src/Matchers.js +0 -354
- data/vendor/jasmine/src/MultiReporter.js +0 -35
- data/vendor/jasmine/src/NestedResults.js +0 -80
- data/vendor/jasmine/src/PrettyPrinter.js +0 -122
- data/vendor/jasmine/src/Queue.js +0 -99
- data/vendor/jasmine/src/Reporter.js +0 -31
- data/vendor/jasmine/src/Runner.js +0 -77
- data/vendor/jasmine/src/Spec.js +0 -242
- data/vendor/jasmine/src/Suite.js +0 -82
- data/vendor/jasmine/src/WaitsBlock.js +0 -13
- data/vendor/jasmine/src/WaitsForBlock.js +0 -52
- data/vendor/jasmine/src/base.js +0 -589
- data/vendor/jasmine/src/html/TrivialReporter.js +0 -188
- data/vendor/jasmine/src/html/jasmine.css +0 -166
- data/vendor/jasmine/src/mock-timeout.js +0 -183
- data/vendor/jasmine/src/util.js +0 -67
- data/vendor/jasmine/src/version.json +0 -5
@@ -1,1253 +0,0 @@
|
|
1
|
-
describe("jasmine spec running", function () {
|
2
|
-
var env;
|
3
|
-
var fakeTimer;
|
4
|
-
|
5
|
-
beforeEach(function() {
|
6
|
-
env = new jasmine.Env();
|
7
|
-
env.updateInterval = 0;
|
8
|
-
|
9
|
-
fakeTimer = new jasmine.FakeTimer();
|
10
|
-
env.setTimeout = fakeTimer.setTimeout;
|
11
|
-
env.clearTimeout = fakeTimer.clearTimeout;
|
12
|
-
env.setInterval = fakeTimer.setInterval;
|
13
|
-
env.clearInterval = fakeTimer.clearInterval;
|
14
|
-
});
|
15
|
-
|
16
|
-
it('should assign spec ids sequentially', function() {
|
17
|
-
var it0, it1, it2, it3, it4;
|
18
|
-
env.describe('test suite', function() {
|
19
|
-
it0 = env.it('spec 0', function() {
|
20
|
-
});
|
21
|
-
it1 = env.it('spec 1', function() {
|
22
|
-
});
|
23
|
-
it2 = env.xit('spec 2', function() {
|
24
|
-
});
|
25
|
-
it3 = env.it('spec 3', function() {
|
26
|
-
});
|
27
|
-
});
|
28
|
-
env.describe('test suite 2', function() {
|
29
|
-
it4 = env.it('spec 4', function() {
|
30
|
-
});
|
31
|
-
});
|
32
|
-
|
33
|
-
expect(it0.id).toEqual(0);
|
34
|
-
expect(it1.id).toEqual(1);
|
35
|
-
expect(it2.id).toEqual(2);
|
36
|
-
expect(it3.id).toEqual(3);
|
37
|
-
expect(it4.id).toEqual(4);
|
38
|
-
});
|
39
|
-
|
40
|
-
it("should build up some objects with results we can inspect", function() {
|
41
|
-
|
42
|
-
var specWithNoBody, specWithExpectation, specWithFailingExpectations, specWithMultipleExpectations;
|
43
|
-
|
44
|
-
var suite = env.describe('default current suite', function() {
|
45
|
-
specWithNoBody = env.it('new spec');
|
46
|
-
|
47
|
-
specWithExpectation = env.it('spec with an expectation').runs(function () {
|
48
|
-
var foo = 'bar';
|
49
|
-
this.expect(foo).toEqual('bar');
|
50
|
-
});
|
51
|
-
|
52
|
-
specWithFailingExpectations = env.it('spec with failing expectation').runs(function () {
|
53
|
-
var foo = 'bar';
|
54
|
-
this.expect(foo).toEqual('baz');
|
55
|
-
});
|
56
|
-
|
57
|
-
specWithMultipleExpectations = env.it('spec with multiple assertions').runs(function () {
|
58
|
-
var foo = 'bar';
|
59
|
-
var baz = 'quux';
|
60
|
-
|
61
|
-
this.expect(foo).toEqual('bar');
|
62
|
-
this.expect(baz).toEqual('quux');
|
63
|
-
});
|
64
|
-
});
|
65
|
-
|
66
|
-
suite.execute();
|
67
|
-
|
68
|
-
expect(specWithNoBody.description).toEqual('new spec');
|
69
|
-
|
70
|
-
expect(specWithExpectation.results().getItems().length).toEqual(1); // "Results aren't there after a spec was executed"
|
71
|
-
expect(specWithExpectation.results().getItems()[0].passed()).toEqual(true); // "Results has a result, but it's true"
|
72
|
-
expect(specWithExpectation.results().description).toEqual('spec with an expectation'); // "Spec's results did not get the spec's description"
|
73
|
-
|
74
|
-
expect(specWithFailingExpectations.results().getItems()[0].passed()).toEqual(false); // "Expectation that failed, passed"
|
75
|
-
|
76
|
-
expect(specWithMultipleExpectations.results().getItems().length).toEqual(2); // "Spec doesn't support multiple expectations"
|
77
|
-
});
|
78
|
-
|
79
|
-
it("should work without a runs block", function() {
|
80
|
-
var another_spec;
|
81
|
-
env.describe('default current suite', function() {
|
82
|
-
another_spec = env.it('spec with an expectation', function () {
|
83
|
-
var foo = 'bar';
|
84
|
-
this.expect(foo).toEqual('bar');
|
85
|
-
this.expect(foo).toEqual('baz');
|
86
|
-
});
|
87
|
-
});
|
88
|
-
|
89
|
-
another_spec.execute();
|
90
|
-
another_spec.done = true;
|
91
|
-
|
92
|
-
expect(another_spec.results().getItems().length).toEqual(2);
|
93
|
-
expect(another_spec.results().getItems()[0].passed()).toEqual(true); // "In a spec without a run block, expected first expectation result to be true but was false"
|
94
|
-
expect(another_spec.results().getItems()[1].passed()).toEqual(false); // "In a spec without a run block, expected second expectation result to be false but was true";
|
95
|
-
expect(another_spec.results().description).toEqual('spec with an expectation'); // "In a spec without a run block, results did not include the spec's description";
|
96
|
-
});
|
97
|
-
|
98
|
-
it('should queue waits and runs that it encounters while executing specs', function() {
|
99
|
-
var specWithRunsAndWaits;
|
100
|
-
var foo = 0;
|
101
|
-
env.describe('test async spec', function() {
|
102
|
-
specWithRunsAndWaits = env.it('spec w/ queued statments', function () {
|
103
|
-
this.runs(function () {
|
104
|
-
foo++;
|
105
|
-
});
|
106
|
-
this.waits(500);
|
107
|
-
this.runs(function () {
|
108
|
-
foo++;
|
109
|
-
});
|
110
|
-
this.waits(500);
|
111
|
-
this.runs(function () {
|
112
|
-
foo++;
|
113
|
-
});
|
114
|
-
});
|
115
|
-
});
|
116
|
-
|
117
|
-
expect(foo).toEqual(0);
|
118
|
-
specWithRunsAndWaits.execute();
|
119
|
-
|
120
|
-
expect(foo).toEqual(1);
|
121
|
-
fakeTimer.tick(500);
|
122
|
-
expect(foo).toEqual(2);
|
123
|
-
fakeTimer.tick(500);
|
124
|
-
expect(foo).toEqual(3);
|
125
|
-
});
|
126
|
-
|
127
|
-
it("should run asynchronous tests", function () {
|
128
|
-
var foo = 0;
|
129
|
-
|
130
|
-
var a_spec;
|
131
|
-
env.describe('test async spec', function() {
|
132
|
-
a_spec = env.it('spec w/ queued statments', function () {
|
133
|
-
this.runs(function () {
|
134
|
-
foo++;
|
135
|
-
});
|
136
|
-
this.runs(function () {
|
137
|
-
this.expect(foo).toEqual(1);
|
138
|
-
});
|
139
|
-
});
|
140
|
-
});
|
141
|
-
|
142
|
-
a_spec.execute();
|
143
|
-
|
144
|
-
expect(a_spec.results().getItems().length).toEqual(1); // 'No call to waits(): Spec queue did not run all functions';
|
145
|
-
expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'No call to waits(): Queued expectation failed';
|
146
|
-
|
147
|
-
foo = 0;
|
148
|
-
env.describe('test async spec', function() {
|
149
|
-
a_spec = env.it('spec w/ queued statments', function () {
|
150
|
-
this.runs(function () {
|
151
|
-
fakeTimer.setTimeout(function() {
|
152
|
-
foo++;
|
153
|
-
}, 500);
|
154
|
-
});
|
155
|
-
this.waits(1000);
|
156
|
-
this.runs(function() {
|
157
|
-
this.expect(foo).toEqual(1);
|
158
|
-
});
|
159
|
-
});
|
160
|
-
});
|
161
|
-
|
162
|
-
a_spec.execute();
|
163
|
-
|
164
|
-
expect(a_spec.results().getItems().length).toEqual(0);
|
165
|
-
|
166
|
-
fakeTimer.tick(500);
|
167
|
-
expect(a_spec.results().getItems().length).toEqual(0);
|
168
|
-
|
169
|
-
fakeTimer.tick(500);
|
170
|
-
expect(a_spec.results().getItems().length).toEqual(1); // 'Calling waits(): Spec queue did not run all functions';
|
171
|
-
|
172
|
-
expect(a_spec.results().getItems()[0].passed()).toEqual(true); // 'Calling waits(): Queued expectation failed';
|
173
|
-
|
174
|
-
var bar = 0;
|
175
|
-
var another_spec;
|
176
|
-
env.describe('test async spec', function() {
|
177
|
-
another_spec = env.it('spec w/ queued statments', function () {
|
178
|
-
this.runs(function () {
|
179
|
-
fakeTimer.setTimeout(function() {
|
180
|
-
bar++;
|
181
|
-
}, 250);
|
182
|
-
|
183
|
-
});
|
184
|
-
this.waits(500);
|
185
|
-
this.runs(function () {
|
186
|
-
fakeTimer.setTimeout(function() {
|
187
|
-
bar++;
|
188
|
-
}, 250);
|
189
|
-
});
|
190
|
-
this.waits(500);
|
191
|
-
this.runs(function () {
|
192
|
-
this.expect(bar).toEqual(2);
|
193
|
-
});
|
194
|
-
});
|
195
|
-
});
|
196
|
-
|
197
|
-
|
198
|
-
another_spec.execute();
|
199
|
-
|
200
|
-
fakeTimer.tick(1000);
|
201
|
-
|
202
|
-
expect(another_spec.results().getItems().length).toEqual(1);
|
203
|
-
expect(another_spec.results().getItems()[0].passed()).toEqual(true);
|
204
|
-
|
205
|
-
var baz = 0;
|
206
|
-
var yet_another_spec;
|
207
|
-
env.describe('test async spec', function() {
|
208
|
-
yet_another_spec = env.it('spec w/ async fail', function () {
|
209
|
-
this.runs(function () {
|
210
|
-
fakeTimer.setTimeout(function() {
|
211
|
-
baz++;
|
212
|
-
}, 250);
|
213
|
-
});
|
214
|
-
this.waits(100);
|
215
|
-
this.runs(function() {
|
216
|
-
this.expect(baz).toEqual(1);
|
217
|
-
});
|
218
|
-
});
|
219
|
-
});
|
220
|
-
|
221
|
-
|
222
|
-
yet_another_spec.execute();
|
223
|
-
//tick twice so that second runs gets eval'd first: mockClock bug?
|
224
|
-
fakeTimer.tick(100);
|
225
|
-
fakeTimer.tick(150);
|
226
|
-
|
227
|
-
|
228
|
-
expect(yet_another_spec.results().getItems().length).toEqual(1);
|
229
|
-
expect(yet_another_spec.results().getItems()[0].passed()).toEqual(false);
|
230
|
-
});
|
231
|
-
|
232
|
-
it("testAsyncSpecsWithMockSuite", function () {
|
233
|
-
var bar = 0;
|
234
|
-
var another_spec;
|
235
|
-
env.describe('test async spec', function() {
|
236
|
-
another_spec = env.it('spec w/ queued statments', function () {
|
237
|
-
this.runs(function () {
|
238
|
-
fakeTimer.setTimeout(function() {
|
239
|
-
bar++;
|
240
|
-
}, 250);
|
241
|
-
});
|
242
|
-
this.waits(500);
|
243
|
-
this.runs(function () {
|
244
|
-
fakeTimer.setTimeout(function() {
|
245
|
-
bar++;
|
246
|
-
}, 250);
|
247
|
-
});
|
248
|
-
this.waits(1500);
|
249
|
-
this.runs(function() {
|
250
|
-
this.expect(bar).toEqual(2);
|
251
|
-
});
|
252
|
-
});
|
253
|
-
});
|
254
|
-
|
255
|
-
another_spec.execute();
|
256
|
-
fakeTimer.tick(2000);
|
257
|
-
expect(another_spec.results().getItems().length).toEqual(1);
|
258
|
-
expect(another_spec.results().getItems()[0].passed()).toEqual(true);
|
259
|
-
});
|
260
|
-
|
261
|
-
describe("waitsFor", function() {
|
262
|
-
var latchFunction = function() {
|
263
|
-
return true;
|
264
|
-
};
|
265
|
-
var spec;
|
266
|
-
|
267
|
-
function makeWaitsForSpec() {
|
268
|
-
var args = jasmine.util.argsToArray(arguments);
|
269
|
-
env.describe('suite', function() {
|
270
|
-
spec = env.it('spec', function() {
|
271
|
-
this.waitsFor.apply(this, args);
|
272
|
-
});
|
273
|
-
});
|
274
|
-
env.execute();
|
275
|
-
}
|
276
|
-
|
277
|
-
it("should accept args (latchFunction, timeoutMessage, timeout)", function() {
|
278
|
-
makeWaitsForSpec(latchFunction, "message", 123);
|
279
|
-
var block = spec.queue.blocks[1];
|
280
|
-
expect(block.latchFunction).toBe(latchFunction);
|
281
|
-
expect(block.timeout).toEqual(123);
|
282
|
-
expect(block.message).toEqual('message');
|
283
|
-
});
|
284
|
-
|
285
|
-
it("should accept args (latchFunction, timeout)", function() {
|
286
|
-
makeWaitsForSpec(latchFunction, 123);
|
287
|
-
var block = spec.queue.blocks[1];
|
288
|
-
expect(block.latchFunction).toBe(latchFunction);
|
289
|
-
expect(block.timeout).toEqual(123);
|
290
|
-
expect(block.message).toEqual(null);
|
291
|
-
});
|
292
|
-
|
293
|
-
it("should accept args (latchFunction, timeoutMessage)", function() {
|
294
|
-
env.defaultTimeoutInterval = 4321;
|
295
|
-
makeWaitsForSpec(latchFunction, "message");
|
296
|
-
var block = spec.queue.blocks[1];
|
297
|
-
expect(block.latchFunction).toBe(latchFunction);
|
298
|
-
expect(block.timeout).toEqual(4321);
|
299
|
-
expect(block.message).toEqual('message');
|
300
|
-
});
|
301
|
-
|
302
|
-
it("should accept args (latchFunction)", function() {
|
303
|
-
env.defaultTimeoutInterval = 4321;
|
304
|
-
makeWaitsForSpec(latchFunction);
|
305
|
-
var block = spec.queue.blocks[1];
|
306
|
-
expect(block.latchFunction).toBe(latchFunction);
|
307
|
-
expect(block.timeout).toEqual(4321);
|
308
|
-
expect(block.message).toEqual(null);
|
309
|
-
});
|
310
|
-
|
311
|
-
it("should accept deprecated args order (timeout, latchFunction, timeoutMessage)", function() {
|
312
|
-
makeWaitsForSpec(123, latchFunction, "message");
|
313
|
-
var block = spec.queue.blocks[1];
|
314
|
-
expect(block.latchFunction).toBe(latchFunction);
|
315
|
-
expect(block.timeout).toEqual(123);
|
316
|
-
expect(block.message).toEqual('message');
|
317
|
-
});
|
318
|
-
|
319
|
-
it("testWaitsFor", function() {
|
320
|
-
var doneWaiting = false;
|
321
|
-
var runsBlockExecuted = false;
|
322
|
-
|
323
|
-
var spec;
|
324
|
-
env.describe('foo', function() {
|
325
|
-
spec = env.it('has a waits for', function() {
|
326
|
-
this.runs(function() {
|
327
|
-
});
|
328
|
-
|
329
|
-
this.waitsFor(500, function() {
|
330
|
-
return doneWaiting;
|
331
|
-
});
|
332
|
-
|
333
|
-
this.runs(function() {
|
334
|
-
runsBlockExecuted = true;
|
335
|
-
});
|
336
|
-
});
|
337
|
-
});
|
338
|
-
|
339
|
-
spec.execute();
|
340
|
-
expect(runsBlockExecuted).toEqual(false); //, 'should not have executed runs block yet');
|
341
|
-
fakeTimer.tick(100);
|
342
|
-
doneWaiting = true;
|
343
|
-
fakeTimer.tick(100);
|
344
|
-
expect(runsBlockExecuted).toEqual(true); //, 'should have executed runs block');
|
345
|
-
});
|
346
|
-
|
347
|
-
it("fails with message", function() {
|
348
|
-
var spec;
|
349
|
-
env.describe('foo', function() {
|
350
|
-
spec = env.it('has a waits for', function() {
|
351
|
-
this.runs(function() {
|
352
|
-
});
|
353
|
-
|
354
|
-
this.waitsFor(500, function() {
|
355
|
-
return false; // force a timeout
|
356
|
-
}, 'my awesome condition');
|
357
|
-
|
358
|
-
this.runs(function() {
|
359
|
-
});
|
360
|
-
});
|
361
|
-
});
|
362
|
-
|
363
|
-
spec.execute();
|
364
|
-
fakeTimer.tick(1000);
|
365
|
-
expect(spec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for my awesome condition');
|
366
|
-
});
|
367
|
-
|
368
|
-
it("fails and skips the rest of the spec if timeout is reached and the latch function hasn't returned true", function() {
|
369
|
-
var runsBlockExecuted = false;
|
370
|
-
var subsequentSpecRan = false;
|
371
|
-
|
372
|
-
var timeoutSpec, subsequentSpec;
|
373
|
-
var suite = env.describe('foo', function() {
|
374
|
-
timeoutSpec = env.it('has a waits for', function() {
|
375
|
-
this.runs(function() {
|
376
|
-
});
|
377
|
-
|
378
|
-
this.waitsFor(500, function() {
|
379
|
-
return false;
|
380
|
-
});
|
381
|
-
|
382
|
-
this.runs(function() {
|
383
|
-
runsBlockExecuted = true;
|
384
|
-
});
|
385
|
-
});
|
386
|
-
|
387
|
-
subsequentSpec = env.it('then carries on to the next test', function() {
|
388
|
-
subsequentSpecRan = true;
|
389
|
-
});
|
390
|
-
});
|
391
|
-
|
392
|
-
env.execute();
|
393
|
-
expect(runsBlockExecuted).toEqual(false);
|
394
|
-
fakeTimer.tick(100);
|
395
|
-
expect(runsBlockExecuted).toEqual(false);
|
396
|
-
fakeTimer.tick(400);
|
397
|
-
expect(runsBlockExecuted).toEqual(false);
|
398
|
-
expect(timeoutSpec.results().getItems()[0].message).toEqual('timeout: timed out after 500 msec waiting for something to happen');
|
399
|
-
expect(subsequentSpecRan).toEqual(true);
|
400
|
-
});
|
401
|
-
});
|
402
|
-
|
403
|
-
it("testSpecAfter", function() {
|
404
|
-
var log = "";
|
405
|
-
var spec;
|
406
|
-
var suite = env.describe("has after", function() {
|
407
|
-
spec = env.it('spec with after', function() {
|
408
|
-
this.runs(function() {
|
409
|
-
log += "spec";
|
410
|
-
});
|
411
|
-
});
|
412
|
-
});
|
413
|
-
spec.after(function() {
|
414
|
-
log += "after1";
|
415
|
-
});
|
416
|
-
spec.after(function() {
|
417
|
-
log += "after2";
|
418
|
-
});
|
419
|
-
|
420
|
-
suite.execute();
|
421
|
-
|
422
|
-
expect(log).toEqual("specafter2after1");
|
423
|
-
});
|
424
|
-
|
425
|
-
describe('test suite declaration', function() {
|
426
|
-
var suite;
|
427
|
-
var dummyFunction = function() {
|
428
|
-
};
|
429
|
-
|
430
|
-
it('should give the suite a description', function() {
|
431
|
-
suite = env.describe('one suite description', dummyFunction);
|
432
|
-
expect(suite.description).toEqual('one suite description');
|
433
|
-
});
|
434
|
-
|
435
|
-
it('should enqueue functions for multipart tests and support waits, and run any ready runs() blocks', function() {
|
436
|
-
var foo = 0;
|
437
|
-
var bar = 0;
|
438
|
-
|
439
|
-
suite = env.describe('one suite description', function () {
|
440
|
-
env.it('should be a test with queuedFunctions', function() {
|
441
|
-
this.runs(function() {
|
442
|
-
foo++;
|
443
|
-
});
|
444
|
-
this.waits(100);
|
445
|
-
this.runs(function() {
|
446
|
-
bar++;
|
447
|
-
});
|
448
|
-
});
|
449
|
-
});
|
450
|
-
|
451
|
-
suite.execute();
|
452
|
-
|
453
|
-
expect(foo).toEqual(1);
|
454
|
-
expect(bar).toEqual(0);
|
455
|
-
|
456
|
-
fakeTimer.tick(100);
|
457
|
-
expect(bar).toEqual(1);
|
458
|
-
});
|
459
|
-
|
460
|
-
});
|
461
|
-
|
462
|
-
it("testBeforeAndAfterCallbacks", function () {
|
463
|
-
var suiteWithBefore = env.describe('one suite with a before', function () {
|
464
|
-
|
465
|
-
this.beforeEach(function () {
|
466
|
-
this.foo = 1;
|
467
|
-
});
|
468
|
-
|
469
|
-
env.it('should be a spec', function () {
|
470
|
-
this.runs(function() {
|
471
|
-
this.foo++;
|
472
|
-
this.expect(this.foo).toEqual(2);
|
473
|
-
});
|
474
|
-
});
|
475
|
-
|
476
|
-
env.it('should be another spec', function () {
|
477
|
-
this.runs(function() {
|
478
|
-
this.foo++;
|
479
|
-
this.expect(this.foo).toEqual(2);
|
480
|
-
});
|
481
|
-
});
|
482
|
-
});
|
483
|
-
|
484
|
-
suiteWithBefore.execute();
|
485
|
-
|
486
|
-
var suite = suiteWithBefore;
|
487
|
-
|
488
|
-
expect(suite.results().getItems()[0].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the first spec's foo should have been 2");
|
489
|
-
expect(suite.results().getItems()[1].passed()).toEqual(true); // "testBeforeAndAfterCallbacks: the second spec's this.foo should have been 2");
|
490
|
-
|
491
|
-
|
492
|
-
var foo = 1;
|
493
|
-
var suiteWithAfter = env.describe('one suite with an after_each', function () {
|
494
|
-
|
495
|
-
env.it('should be a spec with an after_each', function () {
|
496
|
-
this.expect(foo).toEqual(1);
|
497
|
-
foo++;
|
498
|
-
this.expect(foo).toEqual(2);
|
499
|
-
});
|
500
|
-
|
501
|
-
env.it('should be another spec with an after_each', function () {
|
502
|
-
this.expect(foo).toEqual(0);
|
503
|
-
foo++;
|
504
|
-
this.expect(foo).toEqual(1);
|
505
|
-
});
|
506
|
-
|
507
|
-
this.afterEach(function () {
|
508
|
-
foo = 0;
|
509
|
-
});
|
510
|
-
});
|
511
|
-
|
512
|
-
suiteWithAfter.execute();
|
513
|
-
|
514
|
-
suite = suiteWithAfter;
|
515
|
-
expect(suite.afterEach.length).toEqual(1);
|
516
|
-
expect(suite.results().getItems()[0].passed()).toEqual(true);
|
517
|
-
expect(suite.results().getItems()[1].passed()).toEqual(true);
|
518
|
-
expect(foo).toEqual(0);
|
519
|
-
|
520
|
-
});
|
521
|
-
|
522
|
-
it('#waits should allow consecutive waits calls', function () {
|
523
|
-
var foo = 0;
|
524
|
-
var waitsSuite = env.describe('suite that waits', function () {
|
525
|
-
env.it('should wait', function() {
|
526
|
-
this.waits(500);
|
527
|
-
this.waits(500);
|
528
|
-
this.runs(function () {
|
529
|
-
foo++;
|
530
|
-
});
|
531
|
-
});
|
532
|
-
});
|
533
|
-
|
534
|
-
waitsSuite.execute();
|
535
|
-
expect(foo).toEqual(0);
|
536
|
-
fakeTimer.tick(500);
|
537
|
-
expect(foo).toEqual(0);
|
538
|
-
fakeTimer.tick(500);
|
539
|
-
|
540
|
-
expect(foo).toEqual(1);
|
541
|
-
});
|
542
|
-
|
543
|
-
it('nested suites', function () {
|
544
|
-
|
545
|
-
var foo = 0;
|
546
|
-
var bar = 0;
|
547
|
-
var baz = 0;
|
548
|
-
var quux = 0;
|
549
|
-
var nested = env.describe('suite', function () {
|
550
|
-
env.describe('nested', function () {
|
551
|
-
env.it('should run nested suites', function () {
|
552
|
-
foo++;
|
553
|
-
});
|
554
|
-
env.it('should run nested suites', function () {
|
555
|
-
bar++;
|
556
|
-
});
|
557
|
-
});
|
558
|
-
|
559
|
-
env.describe('nested 2', function () {
|
560
|
-
env.it('should run suites following nested suites', function () {
|
561
|
-
baz++;
|
562
|
-
});
|
563
|
-
});
|
564
|
-
|
565
|
-
env.it('should run tests following nested suites', function () {
|
566
|
-
quux++;
|
567
|
-
});
|
568
|
-
});
|
569
|
-
|
570
|
-
expect(foo).toEqual(0);
|
571
|
-
expect(bar).toEqual(0);
|
572
|
-
expect(baz).toEqual(0);
|
573
|
-
expect(quux).toEqual(0);
|
574
|
-
nested.execute();
|
575
|
-
|
576
|
-
expect(foo).toEqual(1);
|
577
|
-
expect(bar).toEqual(1);
|
578
|
-
expect(baz).toEqual(1);
|
579
|
-
expect(quux).toEqual(1);
|
580
|
-
});
|
581
|
-
|
582
|
-
describe('#waitsFor should allow consecutive calls', function () {
|
583
|
-
var foo;
|
584
|
-
beforeEach(function () {
|
585
|
-
foo = 0;
|
586
|
-
});
|
587
|
-
|
588
|
-
it('exits immediately (does not stack) if the latchFunction times out', function () {
|
589
|
-
var reachedFirstWaitsFor = false;
|
590
|
-
var reachedSecondWaitsFor = false;
|
591
|
-
env.describe('suite that waits', function () {
|
592
|
-
env.it('should stack timeouts', function() {
|
593
|
-
this.waitsFor(500, function () {
|
594
|
-
reachedFirstWaitsFor = true;
|
595
|
-
return false;
|
596
|
-
});
|
597
|
-
this.waitsFor(500, function () {
|
598
|
-
reachedSecondWaitsFor = true;
|
599
|
-
});
|
600
|
-
this.runs(function () {
|
601
|
-
foo++;
|
602
|
-
});
|
603
|
-
});
|
604
|
-
});
|
605
|
-
|
606
|
-
expect(reachedFirstWaitsFor).toEqual(false);
|
607
|
-
env.execute();
|
608
|
-
|
609
|
-
expect(reachedFirstWaitsFor).toEqual(true);
|
610
|
-
expect(foo).toEqual(0);
|
611
|
-
expect(reachedSecondWaitsFor).toEqual(false);
|
612
|
-
fakeTimer.tick(500);
|
613
|
-
expect(reachedSecondWaitsFor).toEqual(false);
|
614
|
-
expect(foo).toEqual(0);
|
615
|
-
fakeTimer.tick(500);
|
616
|
-
expect(reachedSecondWaitsFor).toEqual(false);
|
617
|
-
expect(foo).toEqual(0);
|
618
|
-
});
|
619
|
-
|
620
|
-
it('stacks latchFunctions', function () {
|
621
|
-
var firstWaitsResult = false;
|
622
|
-
var secondWaitsResult = false;
|
623
|
-
var waitsSuite = env.describe('suite that waits', function () {
|
624
|
-
env.it('spec with waitsFors', function() {
|
625
|
-
this.waitsFor(600, function () {
|
626
|
-
fakeTimer.setTimeout(function () {
|
627
|
-
firstWaitsResult = true;
|
628
|
-
}, 300);
|
629
|
-
return firstWaitsResult;
|
630
|
-
});
|
631
|
-
this.waitsFor(600, function () {
|
632
|
-
fakeTimer.setTimeout(function () {
|
633
|
-
secondWaitsResult = true;
|
634
|
-
}, 300);
|
635
|
-
return secondWaitsResult;
|
636
|
-
});
|
637
|
-
this.runs(function () {
|
638
|
-
foo++;
|
639
|
-
});
|
640
|
-
});
|
641
|
-
});
|
642
|
-
|
643
|
-
expect(firstWaitsResult).toEqual(false);
|
644
|
-
expect(secondWaitsResult).toEqual(false);
|
645
|
-
waitsSuite.execute();
|
646
|
-
|
647
|
-
expect(firstWaitsResult).toEqual(false);
|
648
|
-
expect(secondWaitsResult).toEqual(false);
|
649
|
-
expect(foo).toEqual(0);
|
650
|
-
|
651
|
-
fakeTimer.tick(300);
|
652
|
-
|
653
|
-
expect(firstWaitsResult).toEqual(true);
|
654
|
-
expect(secondWaitsResult).toEqual(false);
|
655
|
-
expect(foo).toEqual(0);
|
656
|
-
|
657
|
-
fakeTimer.tick(300);
|
658
|
-
|
659
|
-
expect(firstWaitsResult).toEqual(true);
|
660
|
-
expect(secondWaitsResult).toEqual(true);
|
661
|
-
expect(foo).toEqual(1);
|
662
|
-
|
663
|
-
});
|
664
|
-
});
|
665
|
-
|
666
|
-
it("#beforeEach should be able to eval runs and waits blocks", function () {
|
667
|
-
var foo = 0;
|
668
|
-
var bar = 0;
|
669
|
-
var suiteWithBefore = env.describe('one suite with a before', function () {
|
670
|
-
this.beforeEach(function () {
|
671
|
-
this.runs(function () {
|
672
|
-
foo++;
|
673
|
-
});
|
674
|
-
this.waits(500);
|
675
|
-
this.runs(function () {
|
676
|
-
foo++;
|
677
|
-
});
|
678
|
-
this.waits(500);
|
679
|
-
});
|
680
|
-
|
681
|
-
env.it('should be a spec', function () {
|
682
|
-
bar = 1;
|
683
|
-
foo++;
|
684
|
-
});
|
685
|
-
|
686
|
-
});
|
687
|
-
|
688
|
-
expect(foo).toEqual(0);
|
689
|
-
expect(bar).toEqual(0);
|
690
|
-
suiteWithBefore.execute();
|
691
|
-
|
692
|
-
expect(bar).toEqual(0);
|
693
|
-
expect(foo).toEqual(1);
|
694
|
-
fakeTimer.tick(500);
|
695
|
-
|
696
|
-
expect(bar).toEqual(0);
|
697
|
-
expect(foo).toEqual(2);
|
698
|
-
fakeTimer.tick(500);
|
699
|
-
expect(bar).toEqual(1);
|
700
|
-
expect(foo).toEqual(3);
|
701
|
-
});
|
702
|
-
|
703
|
-
it("#afterEach should be able to eval runs and waits blocks", function () {
|
704
|
-
var foo = 0;
|
705
|
-
var firstSpecHasRun = false;
|
706
|
-
var secondSpecHasRun = false;
|
707
|
-
var suiteWithAfter = env.describe('one suite with a before', function () {
|
708
|
-
this.afterEach(function () {
|
709
|
-
this.waits(500);
|
710
|
-
this.runs(function () {
|
711
|
-
foo++;
|
712
|
-
});
|
713
|
-
this.waits(500);
|
714
|
-
});
|
715
|
-
|
716
|
-
env.it('should be the first spec', function () {
|
717
|
-
firstSpecHasRun = true;
|
718
|
-
});
|
719
|
-
|
720
|
-
env.it('should be a spec', function () {
|
721
|
-
secondSpecHasRun = true;
|
722
|
-
foo++;
|
723
|
-
});
|
724
|
-
|
725
|
-
});
|
726
|
-
|
727
|
-
expect(firstSpecHasRun).toEqual(false);
|
728
|
-
expect(secondSpecHasRun).toEqual(false);
|
729
|
-
expect(foo).toEqual(0);
|
730
|
-
|
731
|
-
suiteWithAfter.execute();
|
732
|
-
|
733
|
-
|
734
|
-
expect(firstSpecHasRun).toEqual(true);
|
735
|
-
expect(secondSpecHasRun).toEqual(false);
|
736
|
-
expect(foo).toEqual(0);
|
737
|
-
|
738
|
-
fakeTimer.tick(500);
|
739
|
-
|
740
|
-
expect(foo).toEqual(1);
|
741
|
-
expect(secondSpecHasRun).toEqual(false);
|
742
|
-
fakeTimer.tick(500);
|
743
|
-
|
744
|
-
expect(foo).toEqual(2);
|
745
|
-
expect(secondSpecHasRun).toEqual(true);
|
746
|
-
|
747
|
-
});
|
748
|
-
|
749
|
-
it("Spec#after should be able to eval runs and waits blocks", function () {
|
750
|
-
var runsBeforeAfter = false;
|
751
|
-
var firstSpecHasRun = false;
|
752
|
-
var secondSpecHasRun = false;
|
753
|
-
var afterHasRun = false;
|
754
|
-
var suiteWithAfter = env.describe('one suite with a before', function () {
|
755
|
-
|
756
|
-
env.it('should be the first spec', function () {
|
757
|
-
firstSpecHasRun = true;
|
758
|
-
this.after(function () {
|
759
|
-
this.waits(500);
|
760
|
-
this.runs(function () {
|
761
|
-
afterHasRun = true;
|
762
|
-
});
|
763
|
-
this.waits(500);
|
764
|
-
}, true);
|
765
|
-
this.waits(500);
|
766
|
-
this.runs(function () {
|
767
|
-
runsBeforeAfter = true;
|
768
|
-
});
|
769
|
-
});
|
770
|
-
|
771
|
-
env.it('should be a spec', function () {
|
772
|
-
secondSpecHasRun = true;
|
773
|
-
});
|
774
|
-
|
775
|
-
});
|
776
|
-
|
777
|
-
expect(firstSpecHasRun).toEqual(false);
|
778
|
-
expect(runsBeforeAfter).toEqual(false);
|
779
|
-
expect(afterHasRun).toEqual(false);
|
780
|
-
expect(secondSpecHasRun).toEqual(false);
|
781
|
-
|
782
|
-
suiteWithAfter.execute();
|
783
|
-
|
784
|
-
expect(firstSpecHasRun).toEqual(true);
|
785
|
-
expect(runsBeforeAfter).toEqual(false);
|
786
|
-
expect(afterHasRun).toEqual(false);
|
787
|
-
expect(secondSpecHasRun).toEqual(false);
|
788
|
-
|
789
|
-
fakeTimer.tick(500);
|
790
|
-
|
791
|
-
expect(firstSpecHasRun).toEqual(true);
|
792
|
-
expect(runsBeforeAfter).toEqual(true);
|
793
|
-
expect(afterHasRun).toEqual(false);
|
794
|
-
expect(secondSpecHasRun).toEqual(false);
|
795
|
-
|
796
|
-
fakeTimer.tick(500);
|
797
|
-
|
798
|
-
expect(firstSpecHasRun).toEqual(true);
|
799
|
-
expect(runsBeforeAfter).toEqual(true);
|
800
|
-
expect(afterHasRun).toEqual(true);
|
801
|
-
expect(secondSpecHasRun).toEqual(false);
|
802
|
-
|
803
|
-
fakeTimer.tick(500);
|
804
|
-
|
805
|
-
expect(firstSpecHasRun).toEqual(true);
|
806
|
-
expect(runsBeforeAfter).toEqual(true);
|
807
|
-
expect(afterHasRun).toEqual(true);
|
808
|
-
expect(secondSpecHasRun).toEqual(true);
|
809
|
-
});
|
810
|
-
|
811
|
-
it("handles waits", function () {
|
812
|
-
var firstSpecHasRun = false;
|
813
|
-
var secondSpecHasRun = false;
|
814
|
-
var suiteWithAfter = env.describe('one suite with a before', function () {
|
815
|
-
|
816
|
-
env.it('should be the first spec', function () {
|
817
|
-
this.waits(500);
|
818
|
-
this.runs(function () {
|
819
|
-
firstSpecHasRun = true;
|
820
|
-
});
|
821
|
-
});
|
822
|
-
|
823
|
-
env.it('should be a spec', function () {
|
824
|
-
secondSpecHasRun = true;
|
825
|
-
});
|
826
|
-
|
827
|
-
});
|
828
|
-
|
829
|
-
expect(firstSpecHasRun).toEqual(false);
|
830
|
-
expect(secondSpecHasRun).toEqual(false);
|
831
|
-
|
832
|
-
suiteWithAfter.execute();
|
833
|
-
|
834
|
-
expect(firstSpecHasRun).toEqual(false);
|
835
|
-
expect(secondSpecHasRun).toEqual(false);
|
836
|
-
|
837
|
-
fakeTimer.tick(500);
|
838
|
-
|
839
|
-
expect(firstSpecHasRun).toEqual(true);
|
840
|
-
expect(secondSpecHasRun).toEqual(true);
|
841
|
-
});
|
842
|
-
|
843
|
-
it("testBeforeExecutesSafely", function() {
|
844
|
-
var report = "";
|
845
|
-
var suite = env.describe('before fails on first test, passes on second', function() {
|
846
|
-
var counter = 0;
|
847
|
-
this.beforeEach(function() {
|
848
|
-
counter++;
|
849
|
-
if (counter == 1) {
|
850
|
-
throw "before failure";
|
851
|
-
}
|
852
|
-
});
|
853
|
-
env.it("first should not run because before fails", function() {
|
854
|
-
this.runs(function() {
|
855
|
-
report += "first";
|
856
|
-
this.expect(true).toEqual(true);
|
857
|
-
});
|
858
|
-
});
|
859
|
-
env.it("second should run and pass because before passes", function() {
|
860
|
-
this.runs(function() {
|
861
|
-
report += "second";
|
862
|
-
this.expect(true).toEqual(true);
|
863
|
-
});
|
864
|
-
});
|
865
|
-
});
|
866
|
-
|
867
|
-
suite.execute();
|
868
|
-
|
869
|
-
expect(report).toEqual("firstsecond");
|
870
|
-
var suiteResults = suite.results();
|
871
|
-
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
|
872
|
-
expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true);
|
873
|
-
});
|
874
|
-
|
875
|
-
it("testAfterExecutesSafely", function() {
|
876
|
-
var report = "";
|
877
|
-
var suite = env.describe('after fails on first test, then passes', function() {
|
878
|
-
var counter = 0;
|
879
|
-
this.afterEach(function() {
|
880
|
-
counter++;
|
881
|
-
if (counter == 1) {
|
882
|
-
throw "after failure";
|
883
|
-
}
|
884
|
-
});
|
885
|
-
env.it("first should run, expectation passes, but spec fails because after fails", function() {
|
886
|
-
this.runs(function() {
|
887
|
-
report += "first";
|
888
|
-
this.expect(true).toEqual(true);
|
889
|
-
});
|
890
|
-
});
|
891
|
-
env.it("second should run and pass because after passes", function() {
|
892
|
-
this.runs(function() {
|
893
|
-
report += "second";
|
894
|
-
this.expect(true).toEqual(true);
|
895
|
-
});
|
896
|
-
});
|
897
|
-
env.it("third should run and pass because after passes", function() {
|
898
|
-
this.runs(function() {
|
899
|
-
report += "third";
|
900
|
-
this.expect(true).toEqual(true);
|
901
|
-
});
|
902
|
-
});
|
903
|
-
});
|
904
|
-
|
905
|
-
suite.execute();
|
906
|
-
|
907
|
-
expect(report).toEqual("firstsecondthird"); // "all tests should run");
|
908
|
-
//After each errors should not go in spec results because it confuses the count.
|
909
|
-
var suiteResults = suite.results();
|
910
|
-
expect(suiteResults.getItems().length).toEqual(3, 'testAfterExecutesSafely should have results for three specs');
|
911
|
-
|
912
|
-
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st spec should pass");
|
913
|
-
expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd spec should pass");
|
914
|
-
expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd spec should pass");
|
915
|
-
|
916
|
-
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 1st result for 1st suite spec should pass");
|
917
|
-
expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(false, "testAfterExecutesSafely 2nd result for 1st suite spec should fail because afterEach failed");
|
918
|
-
expect(suiteResults.getItems()[1].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 2nd suite spec should pass");
|
919
|
-
expect(suiteResults.getItems()[2].getItems()[0].passed()).toEqual(true, "testAfterExecutesSafely 3rd suite spec should pass");
|
920
|
-
});
|
921
|
-
|
922
|
-
it("should permit nested describes", function() {
|
923
|
-
var actions = [];
|
924
|
-
|
925
|
-
env.beforeEach(function () {
|
926
|
-
actions.push('runner beforeEach');
|
927
|
-
});
|
928
|
-
|
929
|
-
env.afterEach(function () {
|
930
|
-
actions.push('runner afterEach');
|
931
|
-
});
|
932
|
-
|
933
|
-
env.describe('Something', function() {
|
934
|
-
env.beforeEach(function() {
|
935
|
-
actions.push('outer beforeEach');
|
936
|
-
});
|
937
|
-
|
938
|
-
env.afterEach(function() {
|
939
|
-
actions.push('outer afterEach');
|
940
|
-
});
|
941
|
-
|
942
|
-
env.it('does it 1', function() {
|
943
|
-
actions.push('outer it 1');
|
944
|
-
});
|
945
|
-
|
946
|
-
env.describe('Inner 1', function() {
|
947
|
-
env.beforeEach(function() {
|
948
|
-
actions.push('inner 1 beforeEach');
|
949
|
-
});
|
950
|
-
|
951
|
-
env.afterEach(function() {
|
952
|
-
actions.push('inner 1 afterEach');
|
953
|
-
});
|
954
|
-
|
955
|
-
env.it('does it 2', function() {
|
956
|
-
actions.push('inner 1 it');
|
957
|
-
});
|
958
|
-
});
|
959
|
-
|
960
|
-
env.it('does it 3', function() {
|
961
|
-
actions.push('outer it 2');
|
962
|
-
});
|
963
|
-
|
964
|
-
env.describe('Inner 2', function() {
|
965
|
-
env.beforeEach(function() {
|
966
|
-
actions.push('inner 2 beforeEach');
|
967
|
-
});
|
968
|
-
|
969
|
-
env.afterEach(function() {
|
970
|
-
actions.push('inner 2 afterEach');
|
971
|
-
});
|
972
|
-
|
973
|
-
env.it('does it 2', function() {
|
974
|
-
actions.push('inner 2 it');
|
975
|
-
});
|
976
|
-
});
|
977
|
-
});
|
978
|
-
|
979
|
-
env.execute();
|
980
|
-
|
981
|
-
|
982
|
-
var expected = [
|
983
|
-
"runner beforeEach",
|
984
|
-
"outer beforeEach",
|
985
|
-
"outer it 1",
|
986
|
-
"outer afterEach",
|
987
|
-
"runner afterEach",
|
988
|
-
|
989
|
-
"runner beforeEach",
|
990
|
-
"outer beforeEach",
|
991
|
-
"inner 1 beforeEach",
|
992
|
-
"inner 1 it",
|
993
|
-
"inner 1 afterEach",
|
994
|
-
"outer afterEach",
|
995
|
-
"runner afterEach",
|
996
|
-
|
997
|
-
"runner beforeEach",
|
998
|
-
"outer beforeEach",
|
999
|
-
"outer it 2",
|
1000
|
-
"outer afterEach",
|
1001
|
-
"runner afterEach",
|
1002
|
-
|
1003
|
-
"runner beforeEach",
|
1004
|
-
"outer beforeEach",
|
1005
|
-
"inner 2 beforeEach",
|
1006
|
-
"inner 2 it",
|
1007
|
-
"inner 2 afterEach",
|
1008
|
-
"outer afterEach",
|
1009
|
-
"runner afterEach"
|
1010
|
-
];
|
1011
|
-
expect(actions).toEqual(expected);
|
1012
|
-
});
|
1013
|
-
|
1014
|
-
it("should run multiple befores and afters in the order they are declared", function() {
|
1015
|
-
var actions = [];
|
1016
|
-
|
1017
|
-
env.beforeEach(function () {
|
1018
|
-
actions.push('runner beforeEach1');
|
1019
|
-
});
|
1020
|
-
|
1021
|
-
env.afterEach(function () {
|
1022
|
-
actions.push('runner afterEach1');
|
1023
|
-
});
|
1024
|
-
|
1025
|
-
env.beforeEach(function () {
|
1026
|
-
actions.push('runner beforeEach2');
|
1027
|
-
});
|
1028
|
-
|
1029
|
-
env.afterEach(function () {
|
1030
|
-
actions.push('runner afterEach2');
|
1031
|
-
});
|
1032
|
-
|
1033
|
-
env.describe('Something', function() {
|
1034
|
-
env.beforeEach(function() {
|
1035
|
-
actions.push('beforeEach1');
|
1036
|
-
});
|
1037
|
-
|
1038
|
-
env.afterEach(function() {
|
1039
|
-
actions.push('afterEach1');
|
1040
|
-
});
|
1041
|
-
|
1042
|
-
env.beforeEach(function() {
|
1043
|
-
actions.push('beforeEach2');
|
1044
|
-
});
|
1045
|
-
|
1046
|
-
env.afterEach(function() {
|
1047
|
-
actions.push('afterEach2');
|
1048
|
-
});
|
1049
|
-
|
1050
|
-
env.it('does it 1', function() {
|
1051
|
-
actions.push('outer it 1');
|
1052
|
-
});
|
1053
|
-
});
|
1054
|
-
|
1055
|
-
env.execute();
|
1056
|
-
|
1057
|
-
var expected = [
|
1058
|
-
"runner beforeEach1",
|
1059
|
-
"runner beforeEach2",
|
1060
|
-
"beforeEach1",
|
1061
|
-
"beforeEach2",
|
1062
|
-
"outer it 1",
|
1063
|
-
"afterEach2",
|
1064
|
-
"afterEach1",
|
1065
|
-
"runner afterEach2",
|
1066
|
-
"runner afterEach1"
|
1067
|
-
];
|
1068
|
-
expect(actions).toEqual(expected);
|
1069
|
-
});
|
1070
|
-
|
1071
|
-
it("builds up nested names", function() {
|
1072
|
-
var nestedSpec;
|
1073
|
-
env.describe('Test Subject', function() {
|
1074
|
-
env.describe('when under circumstance A', function() {
|
1075
|
-
env.describe('and circumstance B', function() {
|
1076
|
-
nestedSpec = env.it('behaves thusly', function() {
|
1077
|
-
});
|
1078
|
-
});
|
1079
|
-
});
|
1080
|
-
});
|
1081
|
-
|
1082
|
-
expect(nestedSpec.getFullName()).toEqual('Test Subject when under circumstance A and circumstance B behaves thusly.'); //, "Spec.fullName was incorrect: " + nestedSpec.getFullName());
|
1083
|
-
});
|
1084
|
-
|
1085
|
-
it("should skip empty suites", function () {
|
1086
|
-
env.describe('NonEmptySuite1', function() {
|
1087
|
-
env.it('should pass', function() {
|
1088
|
-
this.expect(true).toEqual(true);
|
1089
|
-
});
|
1090
|
-
env.describe('NestedEmptySuite', function() {
|
1091
|
-
});
|
1092
|
-
env.it('should pass', function() {
|
1093
|
-
this.expect(true).toEqual(true);
|
1094
|
-
});
|
1095
|
-
});
|
1096
|
-
|
1097
|
-
env.describe('EmptySuite', function() {
|
1098
|
-
});
|
1099
|
-
|
1100
|
-
env.describe('NonEmptySuite2', function() {
|
1101
|
-
env.it('should pass', function() {
|
1102
|
-
this.expect(true).toEqual(true);
|
1103
|
-
});
|
1104
|
-
});
|
1105
|
-
|
1106
|
-
env.execute();
|
1107
|
-
|
1108
|
-
var runnerResults = env.currentRunner_.results();
|
1109
|
-
expect(runnerResults.totalCount).toEqual(3);
|
1110
|
-
expect(runnerResults.passedCount).toEqual(3);
|
1111
|
-
expect(runnerResults.failedCount).toEqual(0);
|
1112
|
-
});
|
1113
|
-
|
1114
|
-
it("should bind 'this' to the running spec within the spec body", function() {
|
1115
|
-
var spec;
|
1116
|
-
var suite = env.describe('one suite description', function () {
|
1117
|
-
env.it('should be a test with queuedFunctions', function() {
|
1118
|
-
spec = this.runs(function() {
|
1119
|
-
this.foo = 0;
|
1120
|
-
this.foo++;
|
1121
|
-
});
|
1122
|
-
|
1123
|
-
this.runs(function() {
|
1124
|
-
var that = this;
|
1125
|
-
fakeTimer.setTimeout(function() {
|
1126
|
-
that.foo++;
|
1127
|
-
}, 250);
|
1128
|
-
});
|
1129
|
-
|
1130
|
-
this.runs(function() {
|
1131
|
-
this.expect(this.foo).toEqual(2);
|
1132
|
-
});
|
1133
|
-
|
1134
|
-
this.waits(300);
|
1135
|
-
|
1136
|
-
this.runs(function() {
|
1137
|
-
this.expect(this.foo).toEqual(2);
|
1138
|
-
});
|
1139
|
-
});
|
1140
|
-
|
1141
|
-
});
|
1142
|
-
|
1143
|
-
suite.execute();
|
1144
|
-
fakeTimer.tick(600);
|
1145
|
-
expect(spec.foo).toEqual(2);
|
1146
|
-
var suiteResults = suite.results();
|
1147
|
-
expect(suiteResults.getItems()[0].getItems().length).toEqual(2);
|
1148
|
-
expect(suiteResults.getItems()[0].getItems()[0].passed()).toEqual(false);
|
1149
|
-
expect(suiteResults.getItems()[0].getItems()[1].passed()).toEqual(true);
|
1150
|
-
});
|
1151
|
-
|
1152
|
-
it("shouldn't run disabled tests", function() {
|
1153
|
-
var xitSpecWasRun = false;
|
1154
|
-
var suite = env.describe('default current suite', function() {
|
1155
|
-
env.xit('disabled spec').runs(function () {
|
1156
|
-
xitSpecWasRun = true;
|
1157
|
-
});
|
1158
|
-
|
1159
|
-
env.it('enabled spec').runs(function () {
|
1160
|
-
var foo = 'bar';
|
1161
|
-
expect(foo).toEqual('bar');
|
1162
|
-
});
|
1163
|
-
});
|
1164
|
-
|
1165
|
-
suite.execute();
|
1166
|
-
expect(xitSpecWasRun).toEqual(false);
|
1167
|
-
});
|
1168
|
-
|
1169
|
-
it('shouldn\'t execute specs in disabled suites', function() {
|
1170
|
-
var spy = jasmine.createSpy();
|
1171
|
-
var disabledSuite = env.xdescribe('a disabled suite', function() {
|
1172
|
-
env.it('enabled spec, but should not be run', function() {
|
1173
|
-
spy();
|
1174
|
-
});
|
1175
|
-
});
|
1176
|
-
|
1177
|
-
disabledSuite.execute();
|
1178
|
-
|
1179
|
-
expect(spy).not.toHaveBeenCalled();
|
1180
|
-
});
|
1181
|
-
|
1182
|
-
it('#explodes should throw an exception when it is called inside a spec', function() {
|
1183
|
-
var exceptionMessage = false;
|
1184
|
-
var anotherSuite = env.describe('Spec', function () {
|
1185
|
-
env.it('plodes', function() {
|
1186
|
-
try {
|
1187
|
-
this.explodes();
|
1188
|
-
}
|
1189
|
-
catch (e) {
|
1190
|
-
exceptionMessage = e;
|
1191
|
-
}
|
1192
|
-
expect(exceptionMessage).toNotEqual(false);
|
1193
|
-
});
|
1194
|
-
});
|
1195
|
-
|
1196
|
-
anotherSuite.execute();
|
1197
|
-
|
1198
|
-
expect(exceptionMessage).toEqual('explodes function should not have been called');
|
1199
|
-
});
|
1200
|
-
|
1201
|
-
it("should recover gracefully when there are errors in describe functions", function() {
|
1202
|
-
var specs = [];
|
1203
|
-
var superSimpleReporter = new jasmine.Reporter();
|
1204
|
-
superSimpleReporter.reportSpecResults = function(spec) {
|
1205
|
-
specs.push("Spec: " + spec.getFullName());
|
1206
|
-
var results = spec.results().getItems();
|
1207
|
-
for (var i = 0; i < results.length; i++) {
|
1208
|
-
var result = results[i];
|
1209
|
-
specs.push("Result: " + result);
|
1210
|
-
}
|
1211
|
-
};
|
1212
|
-
|
1213
|
-
try {
|
1214
|
-
env.describe("outer1", function() {
|
1215
|
-
env.describe("inner1", function() {
|
1216
|
-
env.it("should thingy", function() {
|
1217
|
-
this.expect(true).toEqual(true);
|
1218
|
-
});
|
1219
|
-
|
1220
|
-
throw new Error("fake error");
|
1221
|
-
});
|
1222
|
-
|
1223
|
-
env.describe("inner2", function() {
|
1224
|
-
env.it("should other thingy", function() {
|
1225
|
-
this.expect(true).toEqual(true);
|
1226
|
-
});
|
1227
|
-
});
|
1228
|
-
});
|
1229
|
-
} catch(e) {
|
1230
|
-
}
|
1231
|
-
|
1232
|
-
env.describe("outer2", function() {
|
1233
|
-
env.it("should xxx", function() {
|
1234
|
-
this.expect(true).toEqual(true);
|
1235
|
-
});
|
1236
|
-
});
|
1237
|
-
|
1238
|
-
env.addReporter(superSimpleReporter);
|
1239
|
-
env.execute();
|
1240
|
-
|
1241
|
-
expect(specs.join('')).toMatch(new RegExp(
|
1242
|
-
'Spec: outer1 inner1 should thingy.' +
|
1243
|
-
'Result: Passed.' +
|
1244
|
-
'Spec: outer1 encountered a declaration exception.' +
|
1245
|
-
'Result: Error: fake error.*' +
|
1246
|
-
'Spec: outer1 inner2 should other thingy.' +
|
1247
|
-
'Result: Passed.' +
|
1248
|
-
'Spec: outer2 should xxx.' +
|
1249
|
-
'Result: Passed.'
|
1250
|
-
));
|
1251
|
-
});
|
1252
|
-
|
1253
|
-
});
|