jasmine-core 2.5.0 → 2.99.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/console/console.js +1 -1
- data/lib/jasmine-core/boot/boot.js +4 -1
- data/lib/jasmine-core/boot.js +5 -2
- data/lib/jasmine-core/jasmine-html.js +95 -31
- data/lib/jasmine-core/jasmine.css +1 -0
- data/lib/jasmine-core/jasmine.js +3635 -1684
- data/lib/jasmine-core/node_boot.js +1 -1
- data/lib/jasmine-core/spec/core/CallTrackerSpec.js +10 -0
- data/lib/jasmine-core/spec/core/ClearStackSpec.js +137 -0
- data/lib/jasmine-core/spec/core/ClockSpec.js +94 -14
- data/lib/jasmine-core/spec/core/DelayedFunctionSchedulerSpec.js +26 -8
- data/lib/jasmine-core/spec/core/EnvSpec.js +142 -10
- data/lib/jasmine-core/spec/core/ExpectationSpec.js +52 -7
- data/lib/jasmine-core/spec/core/GlobalErrorsSpec.js +110 -0
- data/lib/jasmine-core/spec/core/PrettyPrintSpec.js +132 -4
- data/lib/jasmine-core/spec/core/QueueRunnerSpec.js +333 -23
- data/lib/jasmine-core/spec/core/ReportDispatcherSpec.js +16 -1
- data/lib/jasmine-core/spec/core/SpecSpec.js +30 -8
- data/lib/jasmine-core/spec/core/SpyRegistrySpec.js +225 -1
- data/lib/jasmine-core/spec/core/SpySpec.js +44 -2
- data/lib/jasmine-core/spec/core/SpyStrategySpec.js +28 -5
- data/lib/jasmine-core/spec/core/SuiteSpec.js +14 -19
- data/lib/jasmine-core/spec/core/UserContextSpec.js +54 -0
- data/lib/jasmine-core/spec/core/UtilSpec.js +71 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnySpec.js +32 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/AnythingSpec.js +32 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayContainingSpec.js +13 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ArrayWithExactContentsSpec.js +47 -0
- data/lib/jasmine-core/spec/core/asymmetric_equality/ObjectContainingSpec.js +13 -0
- data/lib/jasmine-core/spec/core/integration/CustomMatchersSpec.js +48 -0
- data/lib/jasmine-core/spec/core/integration/EnvSpec.js +339 -38
- data/lib/jasmine-core/spec/core/integration/SpecRunningSpec.js +156 -3
- 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 +231 -8
- data/lib/jasmine-core/spec/core/matchers/nothingSpec.js +8 -0
- data/lib/jasmine-core/spec/core/matchers/toBeCloseToSpec.js +42 -0
- data/lib/jasmine-core/spec/core/matchers/toBeNegativeInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toBePositiveInfinitySpec.js +31 -0
- data/lib/jasmine-core/spec/core/matchers/toEqualSpec.js +780 -4
- data/lib/jasmine-core/spec/core/matchers/toHaveBeenCalledBeforeSpec.js +99 -0
- data/lib/jasmine-core/spec/core/matchers/toThrowErrorSpec.js +37 -0
- data/lib/jasmine-core/spec/helpers/BrowserFlags.js +4 -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/html/HtmlReporterSpec.js +105 -23
- data/lib/jasmine-core/spec/html/SpyRegistryHtmlSpec.js +34 -0
- data/lib/jasmine-core/spec/npmPackage/npmPackageSpec.js +1 -1
- data/lib/jasmine-core/version.rb +1 -1
- metadata +19 -4
@@ -45,7 +45,6 @@ describe("ReportDispatcher", function() {
|
|
45
45
|
dispatcher.provideFallbackReporter(reporter);
|
46
46
|
dispatcher.foo(123, 456);
|
47
47
|
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
48
|
-
|
49
48
|
});
|
50
49
|
|
51
50
|
it("does not call fallback reporting methods when another report is provided", function() {
|
@@ -59,6 +58,22 @@ describe("ReportDispatcher", function() {
|
|
59
58
|
|
60
59
|
expect(reporter.foo).toHaveBeenCalledWith(123, 456);
|
61
60
|
expect(fallbackReporter.foo).not.toHaveBeenCalledWith(123, 456);
|
61
|
+
});
|
62
|
+
|
63
|
+
it("allows registered reporters to be cleared", function() {
|
64
|
+
var dispatcher = new jasmineUnderTest.ReportDispatcher(['foo', 'bar']),
|
65
|
+
reporter1 = jasmine.createSpyObj('reporter1', ['foo', 'bar']),
|
66
|
+
reporter2 = jasmine.createSpyObj('reporter2', ['foo', 'bar']);
|
67
|
+
|
68
|
+
dispatcher.addReporter(reporter1);
|
69
|
+
dispatcher.foo(123);
|
70
|
+
expect(reporter1.foo).toHaveBeenCalledWith(123);
|
71
|
+
|
72
|
+
dispatcher.clearReporters();
|
73
|
+
dispatcher.addReporter(reporter2);
|
74
|
+
dispatcher.bar(456);
|
62
75
|
|
76
|
+
expect(reporter1.bar).not.toHaveBeenCalled();
|
77
|
+
expect(reporter2.bar).toHaveBeenCalledWith(456);
|
63
78
|
});
|
64
79
|
});
|
@@ -103,8 +103,26 @@ describe("Spec", function() {
|
|
103
103
|
|
104
104
|
spec.execute();
|
105
105
|
|
106
|
-
var
|
107
|
-
expect(
|
106
|
+
var options = fakeQueueRunner.calls.mostRecent().args[0];
|
107
|
+
expect(options.queueableFns).toEqual([before, queueableFn]);
|
108
|
+
expect(options.cleanupFns).toEqual([after]);
|
109
|
+
});
|
110
|
+
|
111
|
+
it("tells the queue runner that it's a leaf node", function() {
|
112
|
+
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner'),
|
113
|
+
spec = new jasmineUnderTest.Spec({
|
114
|
+
queueableFn: { fn: function() {} },
|
115
|
+
beforeAndAfterFns: function() {
|
116
|
+
return {befores: [], afters: []}
|
117
|
+
},
|
118
|
+
queueRunnerFactory: fakeQueueRunner
|
119
|
+
});
|
120
|
+
|
121
|
+
spec.execute();
|
122
|
+
|
123
|
+
expect(fakeQueueRunner).toHaveBeenCalledWith(jasmine.objectContaining({
|
124
|
+
isLeaf: true
|
125
|
+
}));
|
108
126
|
});
|
109
127
|
|
110
128
|
it("is marked pending if created without a function body", function() {
|
@@ -123,7 +141,8 @@ describe("Spec", function() {
|
|
123
141
|
});
|
124
142
|
|
125
143
|
it("can be disabled, but still calls callbacks", function() {
|
126
|
-
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner')
|
144
|
+
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner')
|
145
|
+
.and.callFake(function(attrs) { attrs.onComplete(); }),
|
127
146
|
startCallback = jasmine.createSpy('startCallback'),
|
128
147
|
specBody = jasmine.createSpy('specBody'),
|
129
148
|
resultCallback = jasmine.createSpy('resultCallback'),
|
@@ -140,7 +159,7 @@ describe("Spec", function() {
|
|
140
159
|
|
141
160
|
spec.execute();
|
142
161
|
|
143
|
-
expect(fakeQueueRunner).
|
162
|
+
expect(fakeQueueRunner).toHaveBeenCalled();
|
144
163
|
expect(specBody).not.toHaveBeenCalled();
|
145
164
|
|
146
165
|
expect(startCallback).toHaveBeenCalled();
|
@@ -148,7 +167,8 @@ describe("Spec", function() {
|
|
148
167
|
});
|
149
168
|
|
150
169
|
it("can be disabled at execution time by a parent", function() {
|
151
|
-
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner')
|
170
|
+
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner')
|
171
|
+
.and.callFake(function(attrs) { attrs.onComplete(); }),
|
152
172
|
startCallback = jasmine.createSpy('startCallback'),
|
153
173
|
specBody = jasmine.createSpy('specBody'),
|
154
174
|
resultCallback = jasmine.createSpy('resultCallback'),
|
@@ -163,7 +183,7 @@ describe("Spec", function() {
|
|
163
183
|
|
164
184
|
expect(spec.result.status).toBe('disabled');
|
165
185
|
|
166
|
-
expect(fakeQueueRunner).
|
186
|
+
expect(fakeQueueRunner).toHaveBeenCalled();
|
167
187
|
expect(specBody).not.toHaveBeenCalled();
|
168
188
|
|
169
189
|
expect(startCallback).toHaveBeenCalled();
|
@@ -171,7 +191,8 @@ describe("Spec", function() {
|
|
171
191
|
});
|
172
192
|
|
173
193
|
it("can be marked pending, but still calls callbacks when executed", function() {
|
174
|
-
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner')
|
194
|
+
var fakeQueueRunner = jasmine.createSpy('fakeQueueRunner')
|
195
|
+
.and.callFake(function(attrs) { attrs.onComplete(); }),
|
175
196
|
startCallback = jasmine.createSpy('startCallback'),
|
176
197
|
resultCallback = jasmine.createSpy('resultCallback'),
|
177
198
|
spec = new jasmineUnderTest.Spec({
|
@@ -191,7 +212,7 @@ describe("Spec", function() {
|
|
191
212
|
|
192
213
|
spec.execute();
|
193
214
|
|
194
|
-
expect(fakeQueueRunner).
|
215
|
+
expect(fakeQueueRunner).toHaveBeenCalled();
|
195
216
|
|
196
217
|
expect(startCallback).toHaveBeenCalled();
|
197
218
|
expect(resultCallback).toHaveBeenCalledWith({
|
@@ -201,6 +222,7 @@ describe("Spec", function() {
|
|
201
222
|
fullName: 'a suite with a spec',
|
202
223
|
failedExpectations: [],
|
203
224
|
passedExpectations: [],
|
225
|
+
deprecationWarnings: [],
|
204
226
|
pendingReason: ''
|
205
227
|
});
|
206
228
|
});
|
@@ -16,6 +16,22 @@ describe("SpyRegistry", function() {
|
|
16
16
|
}).toThrowError(/No method name supplied/);
|
17
17
|
});
|
18
18
|
|
19
|
+
it("checks that the object is not `null`", function() {
|
20
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
21
|
+
expect(function() {
|
22
|
+
spyRegistry.spyOn(null, 'pants');
|
23
|
+
}).toThrowError(/could not find an object/);
|
24
|
+
});
|
25
|
+
|
26
|
+
it("checks that the method name is not `null`", function() {
|
27
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
28
|
+
subject = {};
|
29
|
+
|
30
|
+
expect(function() {
|
31
|
+
spyRegistry.spyOn(subject, null);
|
32
|
+
}).toThrowError(/No method name supplied/);
|
33
|
+
});
|
34
|
+
|
19
35
|
it("checks for the existence of the method", function() {
|
20
36
|
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
21
37
|
subject = {};
|
@@ -77,6 +93,126 @@ describe("SpyRegistry", function() {
|
|
77
93
|
});
|
78
94
|
});
|
79
95
|
|
96
|
+
describe("#spyOnProperty", function() {
|
97
|
+
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
98
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
99
|
+
|
100
|
+
it("checks for the existence of the object", function() {
|
101
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
102
|
+
expect(function() {
|
103
|
+
spyRegistry.spyOnProperty(void 0, 'pants');
|
104
|
+
}).toThrowError(/could not find an object/);
|
105
|
+
});
|
106
|
+
|
107
|
+
it("checks that a property name was passed", function() {
|
108
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
109
|
+
subject = {};
|
110
|
+
|
111
|
+
expect(function() {
|
112
|
+
spyRegistry.spyOnProperty(subject);
|
113
|
+
}).toThrowError(/No property name supplied/);
|
114
|
+
});
|
115
|
+
|
116
|
+
it("checks for the existence of the method", function() {
|
117
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
118
|
+
subject = {};
|
119
|
+
|
120
|
+
expect(function() {
|
121
|
+
spyRegistry.spyOnProperty(subject, 'pants');
|
122
|
+
}).toThrowError(/property does not exist/);
|
123
|
+
});
|
124
|
+
|
125
|
+
it("checks for the existence of access type", function() {
|
126
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
127
|
+
subject = {};
|
128
|
+
|
129
|
+
Object.defineProperty(subject, 'pants', {
|
130
|
+
get: function() { return 1; },
|
131
|
+
configurable: true
|
132
|
+
});
|
133
|
+
|
134
|
+
expect(function() {
|
135
|
+
spyRegistry.spyOnProperty(subject, 'pants', 'set');
|
136
|
+
}).toThrowError(/does not have access type/);
|
137
|
+
});
|
138
|
+
|
139
|
+
it("checks if it has already been spied upon", function() {
|
140
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
141
|
+
subject = {};
|
142
|
+
|
143
|
+
Object.defineProperty(subject, 'spiedProp', {
|
144
|
+
get: function() { return 1; },
|
145
|
+
configurable: true
|
146
|
+
});
|
147
|
+
|
148
|
+
spyRegistry.spyOnProperty(subject, 'spiedProp');
|
149
|
+
|
150
|
+
expect(function() {
|
151
|
+
spyRegistry.spyOnProperty(subject, 'spiedProp');
|
152
|
+
}).toThrowError(/has already been spied upon/);
|
153
|
+
});
|
154
|
+
|
155
|
+
it("checks if it can be spied upon", function() {
|
156
|
+
var subject = {};
|
157
|
+
|
158
|
+
Object.defineProperty(subject, 'myProp', {
|
159
|
+
get: function() {}
|
160
|
+
});
|
161
|
+
|
162
|
+
Object.defineProperty(subject, 'spiedProp', {
|
163
|
+
get: function() {},
|
164
|
+
configurable: true
|
165
|
+
});
|
166
|
+
|
167
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry();
|
168
|
+
|
169
|
+
expect(function() {
|
170
|
+
spyRegistry.spyOnProperty(subject, 'myProp');
|
171
|
+
}).toThrowError(/is not declared configurable/);
|
172
|
+
|
173
|
+
expect(function() {
|
174
|
+
spyRegistry.spyOnProperty(subject, 'spiedProp');
|
175
|
+
}).not.toThrowError(/is not declared configurable/);
|
176
|
+
});
|
177
|
+
|
178
|
+
it("overrides the property getter on the object and returns the spy", function() {
|
179
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
180
|
+
subject = {},
|
181
|
+
returnValue = 1;
|
182
|
+
|
183
|
+
Object.defineProperty(subject, 'spiedProperty', {
|
184
|
+
get: function() { return returnValue; },
|
185
|
+
configurable: true
|
186
|
+
});
|
187
|
+
|
188
|
+
expect(subject.spiedProperty).toEqual(returnValue);
|
189
|
+
|
190
|
+
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty');
|
191
|
+
var getter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty').get;
|
192
|
+
|
193
|
+
expect(getter).toEqual(spy);
|
194
|
+
expect(subject.spiedProperty).toBeUndefined();
|
195
|
+
});
|
196
|
+
|
197
|
+
it("overrides the property setter on the object and returns the spy", function() {
|
198
|
+
var spyRegistry = new jasmineUnderTest.SpyRegistry(),
|
199
|
+
subject = {},
|
200
|
+
returnValue = 1;
|
201
|
+
|
202
|
+
Object.defineProperty(subject, 'spiedProperty', {
|
203
|
+
get: function() { return returnValue; },
|
204
|
+
set: function() {},
|
205
|
+
configurable: true
|
206
|
+
});
|
207
|
+
|
208
|
+
var spy = spyRegistry.spyOnProperty(subject, 'spiedProperty', 'set');
|
209
|
+
var setter = Object.getOwnPropertyDescriptor(subject, 'spiedProperty').set;
|
210
|
+
|
211
|
+
expect(subject.spiedProperty).toEqual(returnValue);
|
212
|
+
expect(setter).toEqual(spy);
|
213
|
+
});
|
214
|
+
});
|
215
|
+
|
80
216
|
describe("#clearSpies", function() {
|
81
217
|
it("restores the original functions on the spied-upon objects", function() {
|
82
218
|
var spies = [],
|
@@ -127,6 +263,94 @@ describe("SpyRegistry", function() {
|
|
127
263
|
|
128
264
|
expect(subject.hasOwnProperty('spiedFunc')).toBe(false);
|
129
265
|
expect(subject.spiedFunc).toBe(originalFunction);
|
130
|
-
})
|
266
|
+
});
|
267
|
+
|
268
|
+
it("restores the original function when it\'s inherited and cannot be deleted", function() {
|
269
|
+
// IE 8 doesn't support `Object.create` or `Object.defineProperty`
|
270
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
271
|
+
|
272
|
+
var spies = [],
|
273
|
+
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
274
|
+
originalFunction = function() {},
|
275
|
+
subjectParent = {spiedFunc: originalFunction};
|
276
|
+
|
277
|
+
var subject = Object.create(subjectParent);
|
278
|
+
|
279
|
+
spyRegistry.spyOn(subject, 'spiedFunc');
|
280
|
+
|
281
|
+
// simulate a spy that cannot be deleted
|
282
|
+
Object.defineProperty(subject, 'spiedFunc', {
|
283
|
+
configurable: false
|
284
|
+
});
|
285
|
+
|
286
|
+
spyRegistry.clearSpies();
|
287
|
+
|
288
|
+
expect(jasmineUnderTest.isSpy(subject.spiedFunc)).toBe(false);
|
289
|
+
});
|
290
|
+
|
291
|
+
it("restores window.onerror by overwriting, not deleting", function() {
|
292
|
+
function FakeWindow() {
|
293
|
+
}
|
294
|
+
FakeWindow.prototype.onerror = function() {};
|
295
|
+
|
296
|
+
var spies = [],
|
297
|
+
global = new FakeWindow(),
|
298
|
+
spyRegistry = new jasmineUnderTest.SpyRegistry({
|
299
|
+
currentSpies: function() { return spies; },
|
300
|
+
global: global
|
301
|
+
});
|
302
|
+
|
303
|
+
spyRegistry.spyOn(global, 'onerror');
|
304
|
+
spyRegistry.clearSpies();
|
305
|
+
expect(global.onerror).toBe(FakeWindow.prototype.onerror);
|
306
|
+
expect(global.hasOwnProperty('onerror')).toBe(true);
|
307
|
+
});
|
131
308
|
});
|
309
|
+
|
310
|
+
describe('spying on properties', function() {
|
311
|
+
it("restores the original properties on the spied-upon objects", function() {
|
312
|
+
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
313
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
314
|
+
|
315
|
+
var spies = [],
|
316
|
+
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
317
|
+
originalReturn = 1,
|
318
|
+
subject = {};
|
319
|
+
|
320
|
+
Object.defineProperty(subject, 'spiedProp', {
|
321
|
+
get: function() { return originalReturn; },
|
322
|
+
configurable: true
|
323
|
+
});
|
324
|
+
|
325
|
+
spyRegistry.spyOnProperty(subject, 'spiedProp');
|
326
|
+
spyRegistry.clearSpies();
|
327
|
+
|
328
|
+
expect(subject.spiedProp).toBe(originalReturn);
|
329
|
+
});
|
330
|
+
|
331
|
+
it("does not add a property that the spied-upon object didn't originally have", function() {
|
332
|
+
// IE 8 doesn't support `Object.create`
|
333
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
334
|
+
|
335
|
+
var spies = [],
|
336
|
+
spyRegistry = new jasmineUnderTest.SpyRegistry({currentSpies: function() { return spies; }}),
|
337
|
+
originalReturn = 1,
|
338
|
+
subjectParent = {};
|
339
|
+
|
340
|
+
Object.defineProperty(subjectParent, 'spiedProp', {
|
341
|
+
get: function() { return originalReturn; },
|
342
|
+
configurable: true
|
343
|
+
});
|
344
|
+
|
345
|
+
var subject = Object.create(subjectParent);
|
346
|
+
|
347
|
+
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
|
348
|
+
|
349
|
+
spyRegistry.spyOnProperty(subject, 'spiedProp');
|
350
|
+
spyRegistry.clearSpies();
|
351
|
+
|
352
|
+
expect(subject.hasOwnProperty('spiedProp')).toBe(false);
|
353
|
+
expect(subject.spiedProp).toBe(originalReturn);
|
354
|
+
});
|
355
|
+
});
|
132
356
|
});
|
@@ -57,9 +57,39 @@ describe('Spies', function () {
|
|
57
57
|
|
58
58
|
expect(trackSpy.calls.mostRecent().args[0].returnValue).toEqual("return value");
|
59
59
|
});
|
60
|
+
|
61
|
+
it("preserves arity of original function", function () {
|
62
|
+
var functions = [
|
63
|
+
function nullary () {},
|
64
|
+
function unary (arg) {},
|
65
|
+
function binary (arg1, arg2) {},
|
66
|
+
function ternary (arg1, arg2, arg3) {},
|
67
|
+
function quaternary (arg1, arg2, arg3, arg4) {},
|
68
|
+
function quinary (arg1, arg2, arg3, arg4, arg5) {},
|
69
|
+
function senary (arg1, arg2, arg3, arg4, arg5, arg6) {}
|
70
|
+
];
|
71
|
+
|
72
|
+
for (var arity = 0; arity < functions.length; arity++) {
|
73
|
+
var someFunction = functions[arity],
|
74
|
+
spy = jasmineUnderTest.createSpy(someFunction.name, someFunction);
|
75
|
+
|
76
|
+
expect(spy.length).toEqual(arity);
|
77
|
+
}
|
78
|
+
});
|
60
79
|
});
|
61
80
|
|
62
81
|
describe("createSpyObj", function() {
|
82
|
+
it("should create an object with spy methods and corresponding return values when you call jasmine.createSpyObj() with an object", function () {
|
83
|
+
var spyObj = jasmineUnderTest.createSpyObj('BaseName', {'method1': 42, 'method2': 'special sauce' });
|
84
|
+
|
85
|
+
expect(spyObj.method1()).toEqual(42);
|
86
|
+
expect(spyObj.method1.and.identity()).toEqual('BaseName.method1');
|
87
|
+
|
88
|
+
expect(spyObj.method2()).toEqual('special sauce');
|
89
|
+
expect(spyObj.method2.and.identity()).toEqual('BaseName.method2');
|
90
|
+
});
|
91
|
+
|
92
|
+
|
63
93
|
it("should create an object with a bunch of spy methods when you call jasmine.createSpyObj()", function() {
|
64
94
|
var spyObj = jasmineUnderTest.createSpyObj('BaseName', ['method1', 'method2']);
|
65
95
|
|
@@ -76,10 +106,22 @@ describe('Spies', function () {
|
|
76
106
|
expect(spyObj.method2.and.identity()).toEqual('unknown.method2');
|
77
107
|
});
|
78
108
|
|
79
|
-
it("should throw if you do not pass an array argument", function() {
|
109
|
+
it("should throw if you do not pass an array or object argument", function() {
|
80
110
|
expect(function() {
|
81
111
|
jasmineUnderTest.createSpyObj('BaseName');
|
82
|
-
}).toThrow("createSpyObj requires a non-empty array of method names to create spies for");
|
112
|
+
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
113
|
+
});
|
114
|
+
|
115
|
+
it("should throw if you pass an empty array argument", function() {
|
116
|
+
expect(function() {
|
117
|
+
jasmineUnderTest.createSpyObj('BaseName', []);
|
118
|
+
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
119
|
+
});
|
120
|
+
|
121
|
+
it("should throw if you pass an empty object argument", function() {
|
122
|
+
expect(function() {
|
123
|
+
jasmineUnderTest.createSpyObj('BaseName', {});
|
124
|
+
}).toThrow("createSpyObj requires a non-empty array or object of method names to create spies for");
|
83
125
|
});
|
84
126
|
});
|
85
127
|
});
|
@@ -92,16 +92,39 @@ describe("SpyStrategy", function() {
|
|
92
92
|
expect(returnValue).toEqual(67);
|
93
93
|
});
|
94
94
|
|
95
|
+
it("allows a fake async function to be called instead", function(done) {
|
96
|
+
jasmine.getEnv().requireAsyncAwait();
|
97
|
+
var originalFn = jasmine.createSpy("original"),
|
98
|
+
fakeFn = jasmine.createSpy("fake").and.callFake(eval("async () => { return 67; }")),
|
99
|
+
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
100
|
+
returnValue;
|
101
|
+
|
102
|
+
spyStrategy.callFake(fakeFn);
|
103
|
+
spyStrategy.exec().then(function (returnValue) {
|
104
|
+
expect(originalFn).not.toHaveBeenCalled();
|
105
|
+
expect(fakeFn).toHaveBeenCalled();
|
106
|
+
expect(returnValue).toEqual(67);
|
107
|
+
done();
|
108
|
+
}).catch(function (err) {
|
109
|
+
done.fail(err);
|
110
|
+
})
|
111
|
+
});
|
112
|
+
|
95
113
|
it('throws an error when a non-function is passed to callFake strategy', function() {
|
96
114
|
var originalFn = jasmine.createSpy('original'),
|
115
|
+
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn}),
|
97
116
|
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
|
98
117
|
|
99
|
-
|
100
|
-
|
101
|
-
|
118
|
+
spyOn(jasmineUnderTest, 'isFunction_').and.returnValue(false);
|
119
|
+
spyOn(jasmineUnderTest, 'isAsyncFunction_').and.returnValue(false);
|
120
|
+
|
121
|
+
expect(function () {
|
122
|
+
spyStrategy.callFake(function() {});
|
123
|
+
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
102
124
|
|
103
|
-
|
104
|
-
|
125
|
+
expect(function () {
|
126
|
+
spyStrategy.callFake(function() {});
|
127
|
+
}).toThrowError(/^Argument passed to callFake should be a function, got/);
|
105
128
|
});
|
106
129
|
|
107
130
|
it("allows a return to plan stubbing after another strategy", function() {
|
@@ -83,13 +83,6 @@ describe("Suite", function() {
|
|
83
83
|
expect(suite.getResult().status).toBe('finished');
|
84
84
|
});
|
85
85
|
|
86
|
-
it("retrieves a result with disabled status", function() {
|
87
|
-
var suite = new jasmineUnderTest.Suite({});
|
88
|
-
suite.disable();
|
89
|
-
|
90
|
-
expect(suite.getResult().status).toBe('disabled');
|
91
|
-
});
|
92
|
-
|
93
86
|
it("retrieves a result with pending status", function() {
|
94
87
|
var suite = new jasmineUnderTest.Suite({});
|
95
88
|
suite.pend();
|
@@ -97,23 +90,15 @@ describe("Suite", function() {
|
|
97
90
|
expect(suite.getResult().status).toBe('pending');
|
98
91
|
});
|
99
92
|
|
100
|
-
it("
|
101
|
-
var suite = new jasmineUnderTest.Suite({});
|
102
|
-
suite.disable();
|
103
|
-
suite.pend();
|
104
|
-
|
105
|
-
expect(suite.getResult().status).toBe('disabled');
|
106
|
-
});
|
107
|
-
|
108
|
-
it("is executable if not disabled", function() {
|
93
|
+
it("is executable if not pending", function() {
|
109
94
|
var suite = new jasmineUnderTest.Suite({});
|
110
95
|
|
111
96
|
expect(suite.isExecutable()).toBe(true);
|
112
97
|
});
|
113
98
|
|
114
|
-
it("is not executable if
|
99
|
+
it("is not executable if pending", function() {
|
115
100
|
var suite = new jasmineUnderTest.Suite({});
|
116
|
-
suite.
|
101
|
+
suite.pend();
|
117
102
|
|
118
103
|
expect(suite.isExecutable()).toBe(false);
|
119
104
|
});
|
@@ -156,5 +141,15 @@ describe("Suite", function() {
|
|
156
141
|
suite.onException(new jasmineUnderTest.errors.ExpectationFailed());
|
157
142
|
|
158
143
|
expect(suite.getResult().failedExpectations).toEqual([]);
|
159
|
-
})
|
144
|
+
});
|
145
|
+
|
146
|
+
describe('#sharedUserContext', function() {
|
147
|
+
beforeEach(function() {
|
148
|
+
this.suite = new jasmineUnderTest.Suite({});
|
149
|
+
});
|
150
|
+
|
151
|
+
it('returns a UserContext', function() {
|
152
|
+
expect(this.suite.sharedUserContext().constructor).toBe(jasmineUnderTest.UserContext);
|
153
|
+
});
|
154
|
+
});
|
160
155
|
});
|
@@ -0,0 +1,54 @@
|
|
1
|
+
describe("UserContext", function() {
|
2
|
+
it("Behaves just like an plain object", function() {
|
3
|
+
var context = new jasmineUnderTest.UserContext(),
|
4
|
+
properties = [];
|
5
|
+
|
6
|
+
for (var prop in context) {
|
7
|
+
if (obj.hasOwnProperty(prop)) {
|
8
|
+
properties.push(prop);
|
9
|
+
}
|
10
|
+
}
|
11
|
+
|
12
|
+
expect(properties).toEqual([]);
|
13
|
+
});
|
14
|
+
|
15
|
+
describe('.fromExisting', function() {
|
16
|
+
describe('when using an already built context as model', function() {
|
17
|
+
beforeEach(function() {
|
18
|
+
this.context = new jasmineUnderTest.UserContext();
|
19
|
+
this.context.key = 'value';
|
20
|
+
this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
|
21
|
+
});
|
22
|
+
|
23
|
+
it('returns a cloned object', function() {
|
24
|
+
expect(this.cloned).toEqual(this.context);
|
25
|
+
});
|
26
|
+
|
27
|
+
it('does not return the same object', function() {
|
28
|
+
expect(this.cloned).not.toBe(this.context);
|
29
|
+
});
|
30
|
+
});
|
31
|
+
|
32
|
+
describe('when using a regular object as parameter', function() {
|
33
|
+
beforeEach(function() {
|
34
|
+
this.context = {};
|
35
|
+
this.value = 'value'
|
36
|
+
this.context.key = this.value;
|
37
|
+
this.cloned = jasmineUnderTest.UserContext.fromExisting(this.context);
|
38
|
+
});
|
39
|
+
|
40
|
+
it('returns an object with the same attributes', function() {
|
41
|
+
expect(this.cloned.key).toEqual(this.value);
|
42
|
+
});
|
43
|
+
|
44
|
+
it('does not return the same object', function() {
|
45
|
+
expect(this.cloned).not.toBe(this.context);
|
46
|
+
});
|
47
|
+
|
48
|
+
it('returns an UserContext', function() {
|
49
|
+
expect(this.cloned.constructor).toBe(jasmineUnderTest.UserContext);
|
50
|
+
});
|
51
|
+
});
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
@@ -15,6 +15,22 @@ describe("jasmineUnderTest.util", function() {
|
|
15
15
|
});
|
16
16
|
});
|
17
17
|
|
18
|
+
describe("isObject_", function() {
|
19
|
+
it("should return true if the argument is an object", function() {
|
20
|
+
expect(jasmineUnderTest.isObject_({})).toBe(true);
|
21
|
+
expect(jasmineUnderTest.isObject_({an: "object"})).toBe(true);
|
22
|
+
});
|
23
|
+
|
24
|
+
it("should return false if the argument is not an object", function() {
|
25
|
+
expect(jasmineUnderTest.isObject_(undefined)).toBe(false);
|
26
|
+
expect(jasmineUnderTest.isObject_([])).toBe(false);
|
27
|
+
expect(jasmineUnderTest.isObject_(function() {})).toBe(false);
|
28
|
+
expect(jasmineUnderTest.isObject_('foo')).toBe(false);
|
29
|
+
expect(jasmineUnderTest.isObject_(5)).toBe(false);
|
30
|
+
expect(jasmineUnderTest.isObject_(null)).toBe(false);
|
31
|
+
});
|
32
|
+
});
|
33
|
+
|
18
34
|
describe("isUndefined", function() {
|
19
35
|
it("reports if a variable is defined", function() {
|
20
36
|
var a;
|
@@ -25,4 +41,59 @@ describe("jasmineUnderTest.util", function() {
|
|
25
41
|
expect(jasmineUnderTest.util.isUndefined(undefined)).toBe(false);
|
26
42
|
});
|
27
43
|
});
|
44
|
+
|
45
|
+
describe("getPropertyDescriptor", function() {
|
46
|
+
// IE 8 doesn't support `definePropery` on non-DOM nodes
|
47
|
+
if (jasmine.getEnv().ieVersion < 9) { return; }
|
48
|
+
|
49
|
+
it("get property descriptor from object", function() {
|
50
|
+
var obj = {prop: 1},
|
51
|
+
actual = jasmineUnderTest.util.getPropertyDescriptor(obj, 'prop'),
|
52
|
+
expected = Object.getOwnPropertyDescriptor(obj, 'prop');
|
53
|
+
|
54
|
+
expect(actual).toEqual(expected);
|
55
|
+
});
|
56
|
+
|
57
|
+
it("get property descriptor from object property", function() {
|
58
|
+
var proto = {prop: 1},
|
59
|
+
obj = Object.create(proto),
|
60
|
+
actual = jasmineUnderTest.util.getPropertyDescriptor(proto, 'prop'),
|
61
|
+
expected = Object.getOwnPropertyDescriptor(proto, 'prop');
|
62
|
+
|
63
|
+
expect(actual).toEqual(expected);
|
64
|
+
});
|
65
|
+
});
|
66
|
+
|
67
|
+
describe("objectDifference", function() {
|
68
|
+
it("given two objects A and B, returns the properties in A not present in B", function() {
|
69
|
+
var a = {
|
70
|
+
foo: 3,
|
71
|
+
bar: 4,
|
72
|
+
baz: 5
|
73
|
+
};
|
74
|
+
|
75
|
+
var b = {
|
76
|
+
bar: 6,
|
77
|
+
quux: 7
|
78
|
+
};
|
79
|
+
|
80
|
+
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({foo: 3, baz: 5})
|
81
|
+
});
|
82
|
+
|
83
|
+
it("only looks at own properties of both objects", function() {
|
84
|
+
function Foo() {}
|
85
|
+
|
86
|
+
Foo.prototype.x = 1;
|
87
|
+
Foo.prototype.y = 2;
|
88
|
+
|
89
|
+
var a = new Foo();
|
90
|
+
a.x = 1;
|
91
|
+
|
92
|
+
var b = new Foo();
|
93
|
+
b.y = 2;
|
94
|
+
|
95
|
+
expect(jasmineUnderTest.util.objectDifference(a, b)).toEqual({x: 1});
|
96
|
+
expect(jasmineUnderTest.util.objectDifference(b, a)).toEqual({y: 2});
|
97
|
+
})
|
98
|
+
})
|
28
99
|
});
|