jasmine-core 2.99.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jasmine-core/boot.js +7 -6
- data/lib/jasmine-core/boot/boot.js +7 -6
- data/lib/jasmine-core/boot/node_boot.js +0 -3
- data/lib/jasmine-core/jasmine-html.js +228 -137
- data/lib/jasmine-core/jasmine.css +11 -5
- data/lib/jasmine-core/jasmine.js +1046 -608
- data/lib/jasmine-core/node_boot.js +0 -3
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +130 -0
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +710 -0
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +286 -0
- data/lib/jasmine-core/spec/core/EnvSpec.js +200 -0
- data/lib/jasmine-core/spec/core/ExceptionFormatterSpec.js +120 -0
- data/lib/jasmine-core/spec/core/ExceptionsSpec.js +46 -0
- data/lib/jasmine-core/spec/core/ExpectationResultSpec.js +61 -0
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +434 -0
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
- data/lib/jasmine-core/spec/core/JsApiReporterSpec.js +259 -0
- data/lib/jasmine-core/spec/core/MockDateSpec.js +200 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +332 -0
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +670 -0
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +140 -0
- data/lib/jasmine-core/spec/core/SpecSpec.js +407 -0
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +364 -0
- data/lib/jasmine-core/spec/core/SpySpec.js +177 -0
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +202 -0
- data/lib/jasmine-core/spec/core/StackTraceSpec.js +166 -0
- data/lib/jasmine-core/spec/core/SuiteSpec.js +123 -0
- data/lib/jasmine-core/spec/core/TimerSpec.js +31 -0
- data/lib/jasmine-core/spec/core/TreeProcessorSpec.js +794 -0
- data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +105 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +91 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +76 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +52 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +99 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/StringMatchingSpec.js +27 -0
- data/lib/jasmine-core/spec/core/formatErrorMsgSpec.js +13 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +200 -0
- data/lib/jasmine-core/spec/core/integration/CustomSpyStrategiesSpec.js +138 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +2344 -0
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +976 -0
- data/lib/jasmine-core/spec/core/matchers/DiffBuilderSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/NullDiffBuilderSpec.js +13 -0
- data/lib/jasmine-core/spec/core/matchers/ObjectPathSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/matchersUtilSpec.js +645 -0
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +93 -0
- data/lib/jasmine-core/spec/core/matchers/toBeDefinedSpec.js +18 -0
- data/lib/jasmine-core/spec/core/matchers/toBeFalsySpec.js +38 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanOrEqualSpec.js +29 -0
- data/lib/jasmine-core/spec/core/matchers/toBeGreaterThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanOrEqualSpec.js +29 -0
- data/lib/jasmine-core/spec/core/matchers/toBeLessThanSpec.js +20 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNaNSpec.js +37 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNullSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBeSpec.js +17 -0
- data/lib/jasmine-core/spec/core/matchers/toBeTruthySpec.js +38 -0
- data/lib/jasmine-core/spec/core/matchers/toBeUndefinedSpec.js +18 -0
- data/lib/jasmine-core/spec/core/matchers/toContainSpec.js +26 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +785 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledSpec.js +47 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledTimesSpec.js +86 -0
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledWithSpec.js +67 -0
- data/lib/jasmine-core/spec/core/matchers/toMatchSpec.js +43 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +315 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowMatchingSpec.js +73 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowSpec.js +100 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +15 -0
- data/lib/jasmine-core/spec/helpers/asyncAwait.js +27 -0
- data/lib/jasmine-core/spec/helpers/checkForMap.js +37 -0
- data/lib/jasmine-core/spec/helpers/checkForSet.js +41 -0
- data/lib/jasmine-core/spec/helpers/checkForSymbol.js +28 -0
- data/lib/jasmine-core/spec/helpers/checkForTypedArrays.js +20 -0
- data/lib/jasmine-core/spec/helpers/defineJasmineUnderTest.js +6 -0
- data/lib/jasmine-core/spec/helpers/integrationMatchers.js +43 -0
- data/lib/jasmine-core/spec/helpers/nodeDefineJasmineUnderTest.js +30 -0
- data/lib/jasmine-core/spec/html/HtmlReporterSpec.js +1261 -0
- data/lib/jasmine-core/spec/html/HtmlSpecFilterSpec.js +18 -0
- data/lib/jasmine-core/spec/html/MatchersHtmlSpec.js +37 -0
- data/lib/jasmine-core/spec/html/PrettyPrintHtmlSpec.js +27 -0
- data/lib/jasmine-core/spec/html/QueryStringSpec.js +72 -0
- data/lib/jasmine-core/spec/html/ResultsNodeSpec.js +62 -0
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +39 -0
- data/lib/jasmine-core/spec/html/matchers/toHaveClassSpec.js +48 -0
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +101 -0
- data/lib/jasmine-core/spec/performance/large_object_test.js +36 -0
- data/lib/jasmine-core/spec/performance/performance_test.js +10 -0
- data/lib/jasmine-core/version.rb +1 -1
- metadata +88 -4
- data/lib/console/console.js +0 -190
@@ -0,0 +1,110 @@
|
|
1
|
+
describe("GlobalErrors", function() {
|
2
|
+
it("calls the added handler on error", function() {
|
3
|
+
var fakeGlobal = { onerror: null },
|
4
|
+
handler = jasmine.createSpy('errorHandler'),
|
5
|
+
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
6
|
+
|
7
|
+
errors.install();
|
8
|
+
errors.pushListener(handler);
|
9
|
+
|
10
|
+
fakeGlobal.onerror('foo');
|
11
|
+
|
12
|
+
expect(handler).toHaveBeenCalledWith('foo');
|
13
|
+
});
|
14
|
+
|
15
|
+
it("only calls the most recent handler", function() {
|
16
|
+
var fakeGlobal = { onerror: null },
|
17
|
+
handler1 = jasmine.createSpy('errorHandler1'),
|
18
|
+
handler2 = jasmine.createSpy('errorHandler2'),
|
19
|
+
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
20
|
+
|
21
|
+
errors.install();
|
22
|
+
errors.pushListener(handler1);
|
23
|
+
errors.pushListener(handler2);
|
24
|
+
|
25
|
+
fakeGlobal.onerror('foo');
|
26
|
+
|
27
|
+
expect(handler1).not.toHaveBeenCalled();
|
28
|
+
expect(handler2).toHaveBeenCalledWith('foo');
|
29
|
+
});
|
30
|
+
|
31
|
+
it("calls previous handlers when one is removed", function() {
|
32
|
+
var fakeGlobal = { onerror: null },
|
33
|
+
handler1 = jasmine.createSpy('errorHandler1'),
|
34
|
+
handler2 = jasmine.createSpy('errorHandler2'),
|
35
|
+
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
36
|
+
|
37
|
+
errors.install();
|
38
|
+
errors.pushListener(handler1);
|
39
|
+
errors.pushListener(handler2);
|
40
|
+
|
41
|
+
errors.popListener();
|
42
|
+
|
43
|
+
fakeGlobal.onerror('foo');
|
44
|
+
|
45
|
+
expect(handler1).toHaveBeenCalledWith('foo');
|
46
|
+
expect(handler2).not.toHaveBeenCalled();
|
47
|
+
});
|
48
|
+
|
49
|
+
it("uninstalls itself, putting back a previous callback", function() {
|
50
|
+
var originalCallback = jasmine.createSpy('error'),
|
51
|
+
fakeGlobal = { onerror: originalCallback },
|
52
|
+
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
53
|
+
|
54
|
+
expect(fakeGlobal.onerror).toBe(originalCallback);
|
55
|
+
|
56
|
+
errors.install();
|
57
|
+
|
58
|
+
expect(fakeGlobal.onerror).not.toBe(originalCallback);
|
59
|
+
|
60
|
+
errors.uninstall();
|
61
|
+
|
62
|
+
expect(fakeGlobal.onerror).toBe(originalCallback);
|
63
|
+
});
|
64
|
+
|
65
|
+
it("rethrows the original error when there is no handler", function() {
|
66
|
+
var fakeGlobal = { },
|
67
|
+
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
68
|
+
originalError = new Error('nope');
|
69
|
+
|
70
|
+
errors.install();
|
71
|
+
|
72
|
+
try {
|
73
|
+
fakeGlobal.onerror(originalError);
|
74
|
+
} catch (e) {
|
75
|
+
expect(e).toBe(originalError);
|
76
|
+
}
|
77
|
+
|
78
|
+
errors.uninstall();
|
79
|
+
});
|
80
|
+
|
81
|
+
it("works in node.js", function() {
|
82
|
+
var fakeGlobal = {
|
83
|
+
process: {
|
84
|
+
on: jasmine.createSpy('process.on'),
|
85
|
+
removeListener: jasmine.createSpy('process.removeListener'),
|
86
|
+
listeners: jasmine.createSpy('process.listeners').and.returnValue(['foo']),
|
87
|
+
removeAllListeners: jasmine.createSpy('process.removeAllListeners')
|
88
|
+
}
|
89
|
+
},
|
90
|
+
handler = jasmine.createSpy('errorHandler'),
|
91
|
+
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal);
|
92
|
+
|
93
|
+
errors.install();
|
94
|
+
expect(fakeGlobal.process.on).toHaveBeenCalledWith('uncaughtException', jasmine.any(Function));
|
95
|
+
expect(fakeGlobal.process.listeners).toHaveBeenCalledWith('uncaughtException');
|
96
|
+
expect(fakeGlobal.process.removeAllListeners).toHaveBeenCalledWith('uncaughtException');
|
97
|
+
|
98
|
+
errors.pushListener(handler);
|
99
|
+
|
100
|
+
var addedListener = fakeGlobal.process.on.calls.argsFor(0)[1];
|
101
|
+
addedListener(new Error('bar'));
|
102
|
+
|
103
|
+
expect(handler).toHaveBeenCalledWith(new Error('bar'));
|
104
|
+
|
105
|
+
errors.uninstall();
|
106
|
+
|
107
|
+
expect(fakeGlobal.process.removeListener).toHaveBeenCalledWith('uncaughtException', addedListener);
|
108
|
+
expect(fakeGlobal.process.on).toHaveBeenCalledWith('uncaughtException', 'foo');
|
109
|
+
});
|
110
|
+
});
|
@@ -0,0 +1,259 @@
|
|
1
|
+
xdescribe('JsApiReporter (integration specs)', function() {
|
2
|
+
describe('results', function() {
|
3
|
+
var reporter, spec1, spec2;
|
4
|
+
var env;
|
5
|
+
var suite, nestedSuite, nestedSpec;
|
6
|
+
|
7
|
+
beforeEach(function() {
|
8
|
+
env = new jasmineUnderTest.Env();
|
9
|
+
|
10
|
+
suite = env.describe("top-level suite", function() {
|
11
|
+
spec1 = env.it("spec 1", function() {
|
12
|
+
this.expect(true).toEqual(true);
|
13
|
+
|
14
|
+
});
|
15
|
+
|
16
|
+
spec2 = env.it("spec 2", function() {
|
17
|
+
this.expect(true).toEqual(false);
|
18
|
+
});
|
19
|
+
|
20
|
+
nestedSuite = env.describe("nested suite", function() {
|
21
|
+
nestedSpec = env.it("nested spec", function() {
|
22
|
+
expect(true).toEqual(true);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
|
26
|
+
});
|
27
|
+
|
28
|
+
reporter = new jasmineUnderTest.JsApiReporter({});
|
29
|
+
env.addReporter(reporter);
|
30
|
+
|
31
|
+
env.execute();
|
32
|
+
|
33
|
+
});
|
34
|
+
|
35
|
+
it('results() should return a hash of all results, indexed by spec id', function() {
|
36
|
+
var expectedSpec1Results = {
|
37
|
+
result: "passed"
|
38
|
+
},
|
39
|
+
expectedSpec2Results = {
|
40
|
+
result: "failed"
|
41
|
+
};
|
42
|
+
expect(reporter.results()[spec1.id].result).toEqual('passed');
|
43
|
+
expect(reporter.results()[spec2.id].result).toEqual('failed');
|
44
|
+
});
|
45
|
+
|
46
|
+
it("should return nested suites as children of their parents", function() {
|
47
|
+
expect(reporter.suites()).toEqual([
|
48
|
+
{ id: 0, name: 'top-level suite', type: 'suite',
|
49
|
+
children: [
|
50
|
+
{ id: 0, name: 'spec 1', type: 'spec', children: [ ] },
|
51
|
+
{ id: 1, name: 'spec 2', type: 'spec', children: [ ] },
|
52
|
+
{ id: 1, name: 'nested suite', type: 'suite',
|
53
|
+
children: [
|
54
|
+
{ id: 2, name: 'nested spec', type: 'spec', children: [ ] }
|
55
|
+
]
|
56
|
+
},
|
57
|
+
]
|
58
|
+
}
|
59
|
+
]);
|
60
|
+
});
|
61
|
+
|
62
|
+
describe("#summarizeResult_", function() {
|
63
|
+
it("should summarize a passing result", function() {
|
64
|
+
var result = reporter.results()[spec1.id];
|
65
|
+
var summarizedResult = reporter.summarizeResult_(result);
|
66
|
+
expect(summarizedResult.result).toEqual('passed');
|
67
|
+
expect(summarizedResult.messages.length).toEqual(0);
|
68
|
+
});
|
69
|
+
|
70
|
+
it("should have a stack trace for failing specs", function() {
|
71
|
+
var result = reporter.results()[spec2.id];
|
72
|
+
var summarizedResult = reporter.summarizeResult_(result);
|
73
|
+
expect(summarizedResult.result).toEqual('failed');
|
74
|
+
expect(summarizedResult.messages[0].trace.stack).toEqual(result.messages[0].trace.stack);
|
75
|
+
});
|
76
|
+
|
77
|
+
});
|
78
|
+
});
|
79
|
+
});
|
80
|
+
|
81
|
+
|
82
|
+
describe("JsApiReporter", function() {
|
83
|
+
|
84
|
+
it("knows when a full environment is started", function() {
|
85
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
86
|
+
|
87
|
+
expect(reporter.started).toBe(false);
|
88
|
+
expect(reporter.finished).toBe(false);
|
89
|
+
|
90
|
+
reporter.jasmineStarted();
|
91
|
+
|
92
|
+
expect(reporter.started).toBe(true);
|
93
|
+
expect(reporter.finished).toBe(false);
|
94
|
+
});
|
95
|
+
|
96
|
+
it("knows when a full environment is done", function() {
|
97
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
98
|
+
|
99
|
+
expect(reporter.started).toBe(false);
|
100
|
+
expect(reporter.finished).toBe(false);
|
101
|
+
|
102
|
+
reporter.jasmineStarted();
|
103
|
+
reporter.jasmineDone({});
|
104
|
+
|
105
|
+
expect(reporter.finished).toBe(true);
|
106
|
+
});
|
107
|
+
|
108
|
+
it("defaults to 'loaded' status", function() {
|
109
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
110
|
+
|
111
|
+
expect(reporter.status()).toEqual('loaded');
|
112
|
+
});
|
113
|
+
|
114
|
+
it("reports 'started' when Jasmine has started", function() {
|
115
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
116
|
+
|
117
|
+
reporter.jasmineStarted();
|
118
|
+
|
119
|
+
expect(reporter.status()).toEqual('started');
|
120
|
+
});
|
121
|
+
|
122
|
+
it("reports 'done' when Jasmine is done", function() {
|
123
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
124
|
+
|
125
|
+
reporter.jasmineDone({});
|
126
|
+
|
127
|
+
expect(reporter.status()).toEqual('done');
|
128
|
+
});
|
129
|
+
|
130
|
+
it("tracks a suite", function() {
|
131
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
132
|
+
|
133
|
+
reporter.suiteStarted({
|
134
|
+
id: 123,
|
135
|
+
description: "A suite"
|
136
|
+
});
|
137
|
+
|
138
|
+
var suites = reporter.suites();
|
139
|
+
|
140
|
+
expect(suites).toEqual({123: {id: 123, description: "A suite"}});
|
141
|
+
|
142
|
+
reporter.suiteDone({
|
143
|
+
id: 123,
|
144
|
+
description: "A suite",
|
145
|
+
status: 'passed'
|
146
|
+
});
|
147
|
+
|
148
|
+
expect(suites).toEqual({123: {id: 123, description: "A suite", status: 'passed'}});
|
149
|
+
});
|
150
|
+
|
151
|
+
describe("#specResults", function() {
|
152
|
+
var reporter, specResult1, specResult2;
|
153
|
+
beforeEach(function() {
|
154
|
+
reporter = new jasmineUnderTest.JsApiReporter({});
|
155
|
+
specResult1 = {
|
156
|
+
id: 1,
|
157
|
+
description: "A spec"
|
158
|
+
};
|
159
|
+
specResult2 = {
|
160
|
+
id: 2,
|
161
|
+
description: "Another spec"
|
162
|
+
};
|
163
|
+
|
164
|
+
reporter.specDone(specResult1);
|
165
|
+
reporter.specDone(specResult2);
|
166
|
+
});
|
167
|
+
|
168
|
+
it("should return a slice of results", function() {
|
169
|
+
expect(reporter.specResults(0, 1)).toEqual([specResult1]);
|
170
|
+
expect(reporter.specResults(1, 1)).toEqual([specResult2]);
|
171
|
+
});
|
172
|
+
|
173
|
+
describe("when the results do not exist", function() {
|
174
|
+
it("should return a slice of shorter length", function() {
|
175
|
+
expect(reporter.specResults(0, 3)).toEqual([specResult1, specResult2]);
|
176
|
+
expect(reporter.specResults(2, 3)).toEqual([]);
|
177
|
+
});
|
178
|
+
});
|
179
|
+
});
|
180
|
+
|
181
|
+
describe("#suiteResults", function(){
|
182
|
+
var reporter, suiteResult1, suiteResult2;
|
183
|
+
beforeEach(function() {
|
184
|
+
reporter = new jasmineUnderTest.JsApiReporter({});
|
185
|
+
suiteStarted1 = {
|
186
|
+
id: 1
|
187
|
+
};
|
188
|
+
suiteResult1 = {
|
189
|
+
id: 1,
|
190
|
+
status: 'failed',
|
191
|
+
failedExpectations: [{ message: 'My After All Exception' }]
|
192
|
+
};
|
193
|
+
suiteResult2 = {
|
194
|
+
id: 2,
|
195
|
+
status: 'passed'
|
196
|
+
};
|
197
|
+
|
198
|
+
reporter.suiteStarted(suiteStarted1);
|
199
|
+
reporter.suiteDone(suiteResult1);
|
200
|
+
reporter.suiteDone(suiteResult2);
|
201
|
+
});
|
202
|
+
|
203
|
+
it('should not include suite starts', function(){
|
204
|
+
expect(reporter.suiteResults(0,3).length).toEqual(2);
|
205
|
+
});
|
206
|
+
|
207
|
+
it("should return a slice of results", function() {
|
208
|
+
expect(reporter.suiteResults(0, 1)).toEqual([suiteResult1]);
|
209
|
+
expect(reporter.suiteResults(1, 1)).toEqual([suiteResult2]);
|
210
|
+
});
|
211
|
+
|
212
|
+
it("returns nothing for out of bounds indicies", function() {
|
213
|
+
expect(reporter.suiteResults(0, 3)).toEqual([suiteResult1, suiteResult2]);
|
214
|
+
expect(reporter.suiteResults(2, 3)).toEqual([]);
|
215
|
+
});
|
216
|
+
});
|
217
|
+
|
218
|
+
describe("#executionTime", function() {
|
219
|
+
it("should start the timer when jasmine starts", function() {
|
220
|
+
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
221
|
+
reporter = new jasmineUnderTest.JsApiReporter({
|
222
|
+
timer: timerSpy
|
223
|
+
});
|
224
|
+
|
225
|
+
reporter.jasmineStarted();
|
226
|
+
expect(timerSpy.start).toHaveBeenCalled();
|
227
|
+
});
|
228
|
+
|
229
|
+
it("should return the time it took the specs to run, in ms", function() {
|
230
|
+
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
231
|
+
reporter = new jasmineUnderTest.JsApiReporter({
|
232
|
+
timer: timerSpy
|
233
|
+
});
|
234
|
+
|
235
|
+
timerSpy.elapsed.and.returnValue(1000);
|
236
|
+
reporter.jasmineDone();
|
237
|
+
expect(reporter.executionTime()).toEqual(1000);
|
238
|
+
});
|
239
|
+
|
240
|
+
describe("when the specs haven't finished being run", function() {
|
241
|
+
it("should return undefined", function() {
|
242
|
+
var timerSpy = jasmine.createSpyObj('timer', ['start', 'elapsed']),
|
243
|
+
reporter = new jasmineUnderTest.JsApiReporter({
|
244
|
+
timer: timerSpy
|
245
|
+
});
|
246
|
+
|
247
|
+
expect(reporter.executionTime()).toBeUndefined();
|
248
|
+
});
|
249
|
+
});
|
250
|
+
});
|
251
|
+
|
252
|
+
describe('#runDetails', function() {
|
253
|
+
it('should have details about the run', function() {
|
254
|
+
var reporter = new jasmineUnderTest.JsApiReporter({});
|
255
|
+
reporter.jasmineDone({some: {run: 'details'}});
|
256
|
+
expect(reporter.runDetails).toEqual({some: {run: 'details'}});
|
257
|
+
});
|
258
|
+
});
|
259
|
+
});
|
@@ -0,0 +1,200 @@
|
|
1
|
+
describe("FakeDate", function() {
|
2
|
+
it("does not fail if no global date is found", function() {
|
3
|
+
var fakeGlobal = {},
|
4
|
+
mockDate = new jasmineUnderTest.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 jasmineUnderTest.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 jasmineUnderTest.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 jasmineUnderTest.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 jasmineUnderTest.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 jasmineUnderTest.MockDate(fakeGlobal);
|
75
|
+
|
76
|
+
mockDate.install();
|
77
|
+
expect(new fakeGlobal.Date()).toEqual(jasmine.any(Date));
|
78
|
+
expect(new fakeGlobal.Date() instanceof fakeGlobal.Date).toBe(true);
|
79
|
+
});
|
80
|
+
|
81
|
+
it("fakes current time when using Date.now()", function() {
|
82
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
83
|
+
return {
|
84
|
+
getTime: function() {
|
85
|
+
return 1000;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}),
|
89
|
+
fakeGlobal = { Date: globalDate };
|
90
|
+
|
91
|
+
globalDate.now = function() {};
|
92
|
+
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
93
|
+
|
94
|
+
mockDate.install();
|
95
|
+
|
96
|
+
expect(fakeGlobal.Date.now()).toEqual(1000);
|
97
|
+
});
|
98
|
+
|
99
|
+
it("does not stub Date.now() if it doesn't already exist", function() {
|
100
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
101
|
+
return {
|
102
|
+
getTime: function() {
|
103
|
+
return 1000;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}),
|
107
|
+
fakeGlobal = { Date: globalDate },
|
108
|
+
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
109
|
+
|
110
|
+
mockDate.install();
|
111
|
+
|
112
|
+
expect(fakeGlobal.Date.now).toThrowError("Browser does not support Date.now()");
|
113
|
+
});
|
114
|
+
|
115
|
+
it("makes time passes using tick", function() {
|
116
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
117
|
+
return {
|
118
|
+
getTime: function() {
|
119
|
+
return 1000;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
}),
|
123
|
+
fakeGlobal = { Date: globalDate };
|
124
|
+
|
125
|
+
globalDate.now = function() {};
|
126
|
+
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
127
|
+
|
128
|
+
mockDate.install();
|
129
|
+
|
130
|
+
mockDate.tick(100);
|
131
|
+
|
132
|
+
expect(fakeGlobal.Date.now()).toEqual(1100);
|
133
|
+
|
134
|
+
mockDate.tick(1000);
|
135
|
+
|
136
|
+
expect(fakeGlobal.Date.now()).toEqual(2100);
|
137
|
+
});
|
138
|
+
|
139
|
+
it("allows to increase 0 milliseconds using tick", function() {
|
140
|
+
var globalDate = jasmine.createSpy("global Date").and.callFake(function() {
|
141
|
+
return {
|
142
|
+
getTime: function() {
|
143
|
+
return 1000;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
}),
|
147
|
+
fakeGlobal = { Date: globalDate };
|
148
|
+
|
149
|
+
globalDate.now = function() {};
|
150
|
+
var mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
151
|
+
|
152
|
+
mockDate.install();
|
153
|
+
|
154
|
+
mockDate.tick(0);
|
155
|
+
expect(fakeGlobal.Date.now()).toEqual(1000);
|
156
|
+
|
157
|
+
mockDate.tick();
|
158
|
+
expect(fakeGlobal.Date.now()).toEqual(1000);
|
159
|
+
});
|
160
|
+
|
161
|
+
it("allows creation of a Date in a different time than the mocked time", function() {
|
162
|
+
var fakeGlobal = { Date: Date },
|
163
|
+
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
164
|
+
|
165
|
+
mockDate.install();
|
166
|
+
|
167
|
+
var otherDate = new fakeGlobal.Date(2013, 9, 23, 0, 0, 1, 0);
|
168
|
+
expect(otherDate.getTime()).toEqual(new Date(2013, 9, 23, 0, 0, 1, 0).getTime());
|
169
|
+
});
|
170
|
+
|
171
|
+
it("allows creation of a Date that isn't fully specified", function() {
|
172
|
+
var fakeGlobal = { Date: Date },
|
173
|
+
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
174
|
+
|
175
|
+
mockDate.install();
|
176
|
+
|
177
|
+
var otherDate = new fakeGlobal.Date(2013, 9, 23);
|
178
|
+
expect(otherDate.getTime()).toEqual(new Date(2013, 9, 23).getTime());
|
179
|
+
});
|
180
|
+
|
181
|
+
it('allows creation of a Date with millis', function() {
|
182
|
+
var fakeGlobal = { Date: Date },
|
183
|
+
mockDate = new jasmineUnderTest.MockDate(fakeGlobal),
|
184
|
+
now = new Date(2014, 3, 15).getTime();
|
185
|
+
|
186
|
+
mockDate.install();
|
187
|
+
|
188
|
+
var otherDate = new fakeGlobal.Date(now);
|
189
|
+
expect(otherDate.getTime()).toEqual(now);
|
190
|
+
});
|
191
|
+
|
192
|
+
it("copies all Date properties to the mocked date", function() {
|
193
|
+
var fakeGlobal = { Date: Date },
|
194
|
+
mockDate = new jasmineUnderTest.MockDate(fakeGlobal);
|
195
|
+
|
196
|
+
mockDate.install();
|
197
|
+
|
198
|
+
expect(fakeGlobal.Date.UTC(2013, 9, 23)).toEqual(Date.UTC(2013, 9, 23));
|
199
|
+
});
|
200
|
+
});
|