jasmine-core 2.0.0 → 2.0.1
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.
- checksums.yaml +4 -4
- data/lib/console/console.js +27 -22
- data/lib/jasmine-core.js +2 -0
- data/lib/jasmine-core.rb +6 -2
- data/lib/jasmine-core/__init__.py +1 -0
- data/lib/jasmine-core/boot.js +1 -1
- data/lib/jasmine-core/boot/node_boot.js +71 -0
- data/lib/jasmine-core/core.py +60 -0
- data/lib/jasmine-core/example/node_example/spec/PlayerSpec.js +60 -0
- data/lib/jasmine-core/example/node_example/spec/SpecHelper.js +15 -0
- data/lib/jasmine-core/example/node_example/src/Player.js +24 -0
- data/lib/jasmine-core/example/node_example/src/Song.js +9 -0
- data/lib/jasmine-core/jasmine-html.js +104 -73
- data/lib/jasmine-core/jasmine.css +58 -54
- data/lib/jasmine-core/jasmine.js +368 -254
- data/lib/jasmine-core/node_boot.js +93 -0
- data/lib/jasmine-core/spec/console/ConsoleReporterSpec.js +12 -0
- data/lib/jasmine-core/spec/core/AnySpec.js +1 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +103 -17
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +1 -1
- data/lib/jasmine-core/spec/core/EnvSpec.js +14 -14
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +7 -0
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +2 -2
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +34 -0
- data/lib/jasmine-core/spec/core/MockDateSpec.js +179 -0
- data/lib/jasmine-core/spec/core/ObjectContainingSpec.js +6 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +41 -10
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +130 -31
- data/lib/jasmine-core/spec/core/SpecSpec.js +27 -88
- data/lib/jasmine-core/spec/core/TimerSpec.js +18 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +20 -2
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +2 -1
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +3 -2
- data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +2 -1
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +4 -2
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +2 -1
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +17 -3
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +11 -11
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +5 -5
- data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +7 -0
- data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +33 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +155 -35
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +1 -1
- data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
- data/lib/jasmine-core/version.rb +1 -1
- metadata +34 -23
- data/lib/jasmine-core/spec/node_suite.js +0 -187
- data/lib/jasmine-core/spec/support/dev_boot.js +0 -124
@@ -0,0 +1,179 @@
|
|
1
|
+
describe("FakeDate", function() {
|
2
|
+
it("does not fail if no global date is found", function() {
|
3
|
+
var fakeGlobal = {},
|
4
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
5
|
+
|
6
|
+
expect(function() {
|
7
|
+
mockDate.install();
|
8
|
+
mockDate.tick(0);
|
9
|
+
mockDate.uninstall();
|
10
|
+
}).not.toThrow();
|
11
|
+
});
|
12
|
+
|
13
|
+
it("replaces the global Date when it is installed", function() {
|
14
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
15
|
+
return {
|
16
|
+
getTime: function() {}
|
17
|
+
}
|
18
|
+
}),
|
19
|
+
fakeGlobal = { Date: globalDate },
|
20
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
21
|
+
|
22
|
+
expect(fakeGlobal.Date).toEqual(globalDate);
|
23
|
+
mockDate.install();
|
24
|
+
|
25
|
+
expect(fakeGlobal.Date).not.toEqual(globalDate);
|
26
|
+
});
|
27
|
+
|
28
|
+
it("replaces the global Date on uninstall", function() {
|
29
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
30
|
+
return {
|
31
|
+
getTime: function() {}
|
32
|
+
}
|
33
|
+
}),
|
34
|
+
fakeGlobal = { Date: globalDate },
|
35
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
36
|
+
|
37
|
+
mockDate.install();
|
38
|
+
mockDate.uninstall();
|
39
|
+
|
40
|
+
expect(fakeGlobal.Date).toEqual(globalDate);
|
41
|
+
});
|
42
|
+
|
43
|
+
it("takes the current time as the base when installing without parameters", function() {
|
44
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
45
|
+
return {
|
46
|
+
getTime: function() {
|
47
|
+
return 1000;
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}),
|
51
|
+
fakeGlobal = { Date: globalDate },
|
52
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
53
|
+
|
54
|
+
mockDate.install();
|
55
|
+
|
56
|
+
globalDate.calls.reset();
|
57
|
+
new fakeGlobal.Date();
|
58
|
+
expect(globalDate).toHaveBeenCalledWith(1000);
|
59
|
+
});
|
60
|
+
|
61
|
+
it("can accept a date as time base when installing", function() {
|
62
|
+
var fakeGlobal = { Date: Date },
|
63
|
+
mockDate = new j$.MockDate(fakeGlobal),
|
64
|
+
baseDate = new Date();
|
65
|
+
|
66
|
+
spyOn(baseDate, 'getTime').and.returnValue(123);
|
67
|
+
mockDate.install(baseDate);
|
68
|
+
|
69
|
+
expect(new fakeGlobal.Date().getTime()).toEqual(123);
|
70
|
+
});
|
71
|
+
|
72
|
+
it("makes real dates", function() {
|
73
|
+
var fakeGlobal = { Date: Date },
|
74
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
75
|
+
|
76
|
+
mockDate.install();
|
77
|
+
expect(new fakeGlobal.Date()).toEqual(jasmine.any(Date));
|
78
|
+
});
|
79
|
+
|
80
|
+
it("fakes current time when using Date.now()", function() {
|
81
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
82
|
+
return {
|
83
|
+
getTime: function() {
|
84
|
+
return 1000;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}),
|
88
|
+
fakeGlobal = { Date: globalDate };
|
89
|
+
|
90
|
+
globalDate.now = function() {};
|
91
|
+
var mockDate = new j$.MockDate(fakeGlobal);
|
92
|
+
|
93
|
+
mockDate.install();
|
94
|
+
|
95
|
+
expect(fakeGlobal.Date.now()).toEqual(1000);
|
96
|
+
});
|
97
|
+
|
98
|
+
it("does not stub Date.now() if it doesn't already exist", function() {
|
99
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
100
|
+
return {
|
101
|
+
getTime: function() {
|
102
|
+
return 1000;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
}),
|
106
|
+
fakeGlobal = { Date: globalDate },
|
107
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
108
|
+
|
109
|
+
mockDate.install();
|
110
|
+
|
111
|
+
expect(fakeGlobal.Date.now).toThrowError("Browser does not support Date.now()");
|
112
|
+
});
|
113
|
+
|
114
|
+
it("makes time passes using tick", function() {
|
115
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
116
|
+
return {
|
117
|
+
getTime: function() {
|
118
|
+
return 1000;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}),
|
122
|
+
fakeGlobal = { Date: globalDate };
|
123
|
+
|
124
|
+
globalDate.now = function() {};
|
125
|
+
var mockDate = new j$.MockDate(fakeGlobal);
|
126
|
+
|
127
|
+
mockDate.install();
|
128
|
+
|
129
|
+
mockDate.tick(100);
|
130
|
+
|
131
|
+
expect(fakeGlobal.Date.now()).toEqual(1100);
|
132
|
+
|
133
|
+
mockDate.tick(1000);
|
134
|
+
|
135
|
+
expect(fakeGlobal.Date.now()).toEqual(2100);
|
136
|
+
});
|
137
|
+
|
138
|
+
it("allows to increase 0 milliseconds using tick", function() {
|
139
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
140
|
+
return {
|
141
|
+
getTime: function() {
|
142
|
+
return 1000;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
}),
|
146
|
+
fakeGlobal = { Date: globalDate };
|
147
|
+
|
148
|
+
globalDate.now = function() {};
|
149
|
+
var mockDate = new j$.MockDate(fakeGlobal);
|
150
|
+
|
151
|
+
mockDate.install();
|
152
|
+
|
153
|
+
mockDate.tick(0);
|
154
|
+
expect(fakeGlobal.Date.now()).toEqual(1000);
|
155
|
+
|
156
|
+
mockDate.tick();
|
157
|
+
expect(fakeGlobal.Date.now()).toEqual(1000);
|
158
|
+
});
|
159
|
+
|
160
|
+
it("allows to create a Date in a different time than the mocked time", function() {
|
161
|
+
var fakeGlobal = { Date: Date },
|
162
|
+
mockDate = new j$.MockDate(fakeGlobal),
|
163
|
+
baseDate = new Date(2013, 9, 23, 0, 0, 0, 0);
|
164
|
+
|
165
|
+
mockDate.install(baseDate);
|
166
|
+
|
167
|
+
var otherDate = new fakeGlobal.Date(2013, 9, 23, 0, 0, 1, 0);
|
168
|
+
expect(otherDate.getTime()).not.toEqual(baseDate.getTime());
|
169
|
+
});
|
170
|
+
|
171
|
+
it("copies all Date properties to the mocked date", function() {
|
172
|
+
var fakeGlobal = { Date: Date },
|
173
|
+
mockDate = new j$.MockDate(fakeGlobal);
|
174
|
+
|
175
|
+
mockDate.install();
|
176
|
+
|
177
|
+
expect(fakeGlobal.Date.UTC(2013, 9, 23)).toEqual(Date.UTC(2013, 9, 23));
|
178
|
+
});
|
179
|
+
});
|
@@ -61,4 +61,10 @@ describe("ObjectContaining", function() {
|
|
61
61
|
|
62
62
|
expect(containing.jasmineToString()).toMatch("<jasmine.objectContaining");
|
63
63
|
});
|
64
|
+
|
65
|
+
it("matches recursively", function() {
|
66
|
+
var containing = new j$.ObjectContaining({one: new j$.ObjectContaining({two: {}})});
|
67
|
+
|
68
|
+
expect(containing.jasmineMatches({one: {two: {}}})).toBe(true);
|
69
|
+
});
|
64
70
|
});
|
@@ -11,6 +11,7 @@ describe("j$.pp", function () {
|
|
11
11
|
expect(j$.pp(jasmine.undefined)).toEqual("undefined");
|
12
12
|
expect(j$.pp(3)).toEqual("3");
|
13
13
|
expect(j$.pp(-3.14)).toEqual("-3.14");
|
14
|
+
expect(j$.pp(-0)).toEqual("-0");
|
14
15
|
});
|
15
16
|
|
16
17
|
it("should stringify arrays properly", function() {
|
@@ -26,10 +27,10 @@ describe("j$.pp", function () {
|
|
26
27
|
});
|
27
28
|
|
28
29
|
it("should stringify objects properly", function() {
|
29
|
-
expect(j$.pp({foo: 'bar'})).toEqual("{ foo
|
30
|
-
expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("{ foo
|
30
|
+
expect(j$.pp({foo: 'bar'})).toEqual("{ foo: 'bar' }");
|
31
|
+
expect(j$.pp({foo:'bar', baz:3, nullValue: null, undefinedValue: jasmine.undefined})).toEqual("{ foo: 'bar', baz: 3, nullValue: null, undefinedValue: undefined }");
|
31
32
|
expect(j$.pp({foo: function () {
|
32
|
-
}, bar: [1, 2, 3]})).toEqual("{ foo
|
33
|
+
}, bar: [1, 2, 3]})).toEqual("{ foo: Function, bar: [ 1, 2, 3 ] }");
|
33
34
|
});
|
34
35
|
|
35
36
|
it("should not include inherited properties when stringifying an object", function() {
|
@@ -37,7 +38,7 @@ describe("j$.pp", function () {
|
|
37
38
|
SomeClass.prototype.foo = "inherited foo";
|
38
39
|
var instance = new SomeClass();
|
39
40
|
instance.bar = "my own bar";
|
40
|
-
expect(j$.pp(instance)).toEqual("{ bar
|
41
|
+
expect(j$.pp(instance)).toEqual("{ bar: 'my own bar' }");
|
41
42
|
});
|
42
43
|
|
43
44
|
it("should not recurse objects and arrays more deeply than j$.MAX_PRETTY_PRINT_DEPTH", function() {
|
@@ -47,21 +48,42 @@ describe("j$.pp", function () {
|
|
47
48
|
|
48
49
|
try {
|
49
50
|
j$.MAX_PRETTY_PRINT_DEPTH = 2;
|
50
|
-
expect(j$.pp(nestedObject)).toEqual("{ level1
|
51
|
+
expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: Object } }");
|
51
52
|
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, Array ] ]");
|
52
53
|
|
53
54
|
j$.MAX_PRETTY_PRINT_DEPTH = 3;
|
54
|
-
expect(j$.pp(nestedObject)).toEqual("{ level1
|
55
|
+
expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: Object } } }");
|
55
56
|
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, Array ] ] ]");
|
56
57
|
|
57
58
|
j$.MAX_PRETTY_PRINT_DEPTH = 4;
|
58
|
-
expect(j$.pp(nestedObject)).toEqual("{ level1
|
59
|
+
expect(j$.pp(nestedObject)).toEqual("{ level1: { level2: { level3: { level4: 'leaf' } } } }");
|
59
60
|
expect(j$.pp(nestedArray)).toEqual("[ 1, [ 2, [ 3, [ 4, 'leaf' ] ] ] ]");
|
60
61
|
} finally {
|
61
62
|
j$.MAX_PRETTY_PRINT_DEPTH = originalMaxDepth;
|
62
63
|
}
|
63
64
|
});
|
64
65
|
|
66
|
+
it("should stringify immutable circular objects", function(){
|
67
|
+
if(Object.freeze){
|
68
|
+
var frozenObject = {foo: {bar: 'baz'}};
|
69
|
+
frozenObject.circular = frozenObject;
|
70
|
+
frozenObject = Object.freeze(frozenObject);
|
71
|
+
expect(j$.pp(frozenObject)).toEqual("{ foo: { bar: 'baz' }, circular: <circular reference: Object> }");
|
72
|
+
}
|
73
|
+
});
|
74
|
+
|
75
|
+
it("should truncate arrays that are longer than j$.MAX_PRETTY_PRINT_ARRAY_LENGTH", function() {
|
76
|
+
var originalMaxLength = j$.MAX_PRETTY_PRINT_ARRAY_LENGTH;
|
77
|
+
var array = [1, 2, 3];
|
78
|
+
|
79
|
+
try {
|
80
|
+
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 2;
|
81
|
+
expect(j$.pp(array)).toEqual("[ 1, 2, ... ]");
|
82
|
+
} finally {
|
83
|
+
j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = originalMaxLength;
|
84
|
+
}
|
85
|
+
});
|
86
|
+
|
65
87
|
it("should stringify RegExp objects properly", function() {
|
66
88
|
expect(j$.pp(/x|y|z/)).toEqual("/x|y|z/");
|
67
89
|
});
|
@@ -69,7 +91,7 @@ describe("j$.pp", function () {
|
|
69
91
|
it("should indicate circular object references", function() {
|
70
92
|
var sampleValue = {foo: 'hello'};
|
71
93
|
sampleValue.nested = sampleValue;
|
72
|
-
expect(j$.pp(sampleValue)).toEqual("{ foo
|
94
|
+
expect(j$.pp(sampleValue)).toEqual("{ foo: 'hello', nested: <circular reference: Object> }");
|
73
95
|
});
|
74
96
|
|
75
97
|
it("should indicate getters on objects as such", function() {
|
@@ -81,10 +103,10 @@ describe("j$.pp", function () {
|
|
81
103
|
});
|
82
104
|
}
|
83
105
|
if (sampleValue.__defineGetter__) {
|
84
|
-
expect(j$.pp(sampleValue)).toEqual("{ id
|
106
|
+
expect(j$.pp(sampleValue)).toEqual("{ id: 1, calculatedValue: <getter> }");
|
85
107
|
}
|
86
108
|
else {
|
87
|
-
expect(j$.pp(sampleValue)).toEqual("{ id
|
109
|
+
expect(j$.pp(sampleValue)).toEqual("{ id: 1 }");
|
88
110
|
}
|
89
111
|
});
|
90
112
|
|
@@ -121,5 +143,14 @@ describe("j$.pp", function () {
|
|
121
143
|
|
122
144
|
expect(j$.pp(obj)).toEqual("strung");
|
123
145
|
});
|
146
|
+
|
147
|
+
it("should handle objects with null prototype", function() {
|
148
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
149
|
+
|
150
|
+
var obj = Object.create(null);
|
151
|
+
obj.foo = 'bar';
|
152
|
+
|
153
|
+
expect(j$.pp(obj)).toEqual("{ foo: 'bar' }");
|
154
|
+
});
|
124
155
|
});
|
125
156
|
|
@@ -50,31 +50,25 @@ describe("QueueRunner", function() {
|
|
50
50
|
//createSpy('asyncfn').and.callFake(function(done) {});
|
51
51
|
|
52
52
|
var onComplete = jasmine.createSpy('onComplete'),
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
}, 100);
|
73
|
-
},
|
74
|
-
queueRunner = new j$.QueueRunner({
|
75
|
-
fns: [fn1, fn2, fn3],
|
76
|
-
onComplete: onComplete
|
77
|
-
});
|
53
|
+
beforeCallback = jasmine.createSpy('beforeCallback'),
|
54
|
+
fnCallback = jasmine.createSpy('fnCallback'),
|
55
|
+
afterCallback = jasmine.createSpy('afterCallback'),
|
56
|
+
fn1 = function(done) {
|
57
|
+
beforeCallback();
|
58
|
+
setTimeout(done, 100);
|
59
|
+
},
|
60
|
+
fn2 = function(done) {
|
61
|
+
fnCallback();
|
62
|
+
setTimeout(done, 100);
|
63
|
+
},
|
64
|
+
fn3 = function(done) {
|
65
|
+
afterCallback();
|
66
|
+
setTimeout(done, 100);
|
67
|
+
},
|
68
|
+
queueRunner = new j$.QueueRunner({
|
69
|
+
fns: [fn1, fn2, fn3],
|
70
|
+
onComplete: onComplete
|
71
|
+
});
|
78
72
|
|
79
73
|
queueRunner.execute();
|
80
74
|
|
@@ -98,6 +92,112 @@ describe("QueueRunner", function() {
|
|
98
92
|
|
99
93
|
expect(onComplete).toHaveBeenCalled();
|
100
94
|
});
|
95
|
+
|
96
|
+
it("sets a timeout if requested for asynchronous functions so they don't go on forever", function() {
|
97
|
+
var beforeFn = function(done) { },
|
98
|
+
fn = jasmine.createSpy('fn'),
|
99
|
+
onComplete = jasmine.createSpy('onComplete'),
|
100
|
+
onException = jasmine.createSpy('onException'),
|
101
|
+
queueRunner = new j$.QueueRunner({
|
102
|
+
fns: [beforeFn, fn],
|
103
|
+
onComplete: onComplete,
|
104
|
+
onException: onException,
|
105
|
+
enforceTimeout: function() { return true; }
|
106
|
+
});
|
107
|
+
|
108
|
+
queueRunner.execute();
|
109
|
+
expect(fn).not.toHaveBeenCalled();
|
110
|
+
|
111
|
+
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
|
112
|
+
|
113
|
+
expect(onException).toHaveBeenCalledWith(jasmine.any(Error));
|
114
|
+
expect(fn).toHaveBeenCalled();
|
115
|
+
expect(onComplete).toHaveBeenCalled();
|
116
|
+
});
|
117
|
+
|
118
|
+
it("by default does not set a timeout for asynchronous functions", function() {
|
119
|
+
var beforeFn = function(done) { },
|
120
|
+
fn = jasmine.createSpy('fn'),
|
121
|
+
onComplete = jasmine.createSpy('onComplete'),
|
122
|
+
onException = jasmine.createSpy('onException'),
|
123
|
+
queueRunner = new j$.QueueRunner({
|
124
|
+
fns: [beforeFn, fn],
|
125
|
+
onComplete: onComplete,
|
126
|
+
onException: onException,
|
127
|
+
});
|
128
|
+
|
129
|
+
queueRunner.execute();
|
130
|
+
expect(fn).not.toHaveBeenCalled();
|
131
|
+
|
132
|
+
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
|
133
|
+
|
134
|
+
expect(onException).not.toHaveBeenCalled();
|
135
|
+
expect(fn).not.toHaveBeenCalled();
|
136
|
+
expect(onComplete).not.toHaveBeenCalled();
|
137
|
+
});
|
138
|
+
|
139
|
+
it("clears the timeout when an async function throws an exception, to prevent additional onException calls", function() {
|
140
|
+
var fn = function(done) { throw new Error("error!"); },
|
141
|
+
onComplete = jasmine.createSpy('onComplete'),
|
142
|
+
onException = jasmine.createSpy('onException'),
|
143
|
+
queueRunner = new j$.QueueRunner({
|
144
|
+
fns: [fn],
|
145
|
+
onComplete: onComplete,
|
146
|
+
onException: onException
|
147
|
+
});
|
148
|
+
|
149
|
+
queueRunner.execute();
|
150
|
+
|
151
|
+
expect(onComplete).toHaveBeenCalled();
|
152
|
+
expect(onException).toHaveBeenCalled();
|
153
|
+
|
154
|
+
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
|
155
|
+
expect(onException.calls.count()).toEqual(1);
|
156
|
+
});
|
157
|
+
|
158
|
+
it("clears the timeout when the done callback is called", function() {
|
159
|
+
var fn = function(done) { done(); },
|
160
|
+
onComplete = jasmine.createSpy('onComplete'),
|
161
|
+
onException = jasmine.createSpy('onException'),
|
162
|
+
queueRunner = new j$.QueueRunner({
|
163
|
+
fns: [fn],
|
164
|
+
onComplete: onComplete,
|
165
|
+
onException: onException
|
166
|
+
});
|
167
|
+
|
168
|
+
queueRunner.execute();
|
169
|
+
|
170
|
+
expect(onComplete).toHaveBeenCalled();
|
171
|
+
|
172
|
+
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
|
173
|
+
expect(onException).not.toHaveBeenCalled();
|
174
|
+
});
|
175
|
+
|
176
|
+
it("only moves to the next spec the first time you call done", function() {
|
177
|
+
var fn = function(done) {done(); done();},
|
178
|
+
nextFn = jasmine.createSpy('nextFn');
|
179
|
+
queueRunner = new j$.QueueRunner({
|
180
|
+
fns: [fn, nextFn]
|
181
|
+
});
|
182
|
+
|
183
|
+
queueRunner.execute();
|
184
|
+
expect(nextFn.calls.count()).toEqual(1);
|
185
|
+
});
|
186
|
+
|
187
|
+
it("does not move to the next spec if done is called after an exception has ended the spec", function() {
|
188
|
+
var fn = function(done) {
|
189
|
+
setTimeout(done, 1);
|
190
|
+
throw new Error('error!');
|
191
|
+
},
|
192
|
+
nextFn = jasmine.createSpy('nextFn');
|
193
|
+
queueRunner = new j$.QueueRunner({
|
194
|
+
fns: [fn, nextFn]
|
195
|
+
});
|
196
|
+
|
197
|
+
queueRunner.execute();
|
198
|
+
jasmine.clock().tick(1);
|
199
|
+
expect(nextFn.calls.count()).toEqual(1);
|
200
|
+
});
|
101
201
|
});
|
102
202
|
|
103
203
|
it("calls an exception handler when an exception is thrown in a fn", function() {
|
@@ -124,16 +224,15 @@ describe("QueueRunner", function() {
|
|
124
224
|
catchException: function(e) { return false; }
|
125
225
|
});
|
126
226
|
|
127
|
-
expect(
|
227
|
+
expect(queueRunner.execute).toThrow();
|
128
228
|
});
|
129
229
|
|
130
230
|
it("continues running the functions even after an exception is thrown in an async spec", function() {
|
131
231
|
var fn = function(done) { throw new Error("error"); },
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
});
|
232
|
+
nextFn = jasmine.createSpy("nextFunction"),
|
233
|
+
queueRunner = new j$.QueueRunner({
|
234
|
+
fns: [fn, nextFn]
|
235
|
+
});
|
137
236
|
|
138
237
|
queueRunner.execute();
|
139
238
|
expect(nextFn).toHaveBeenCalled();
|