Skip to content
Permalink
Browse files
Jasmine 3: Replace usage of Spec#after
  • Loading branch information
raphinesse committed Sep 28, 2018
1 parent f28706f commit 430620d145fe28ba4f781db736d737906fce4fb0
Showing 3 changed files with 17 additions and 21 deletions.
@@ -19,25 +19,24 @@
*
*/

/* eslint-env jasmine */

// Use this helper module to stub out properties within Jasmine tests.
// Original values will be restored after each test.

var curStubs = null;
var stubs = [];

function removeAllStubs () {
for (var i = curStubs.length - 1, stub; stub = curStubs[i]; --i) { // eslint-disable-line no-cond-assign
for (const stub of stubs) {
stub.obj[stub.key] = stub.value;
}
curStubs = null;
stubs = [];
}

exports.stub = function (obj, key, value) {
if (!curStubs) {
curStubs = [];
jasmine.getEnv().currentSpec.after(removeAllStubs); // eslint-disable-line no-undef
}
afterEach(removeAllStubs);

curStubs.push({
exports.stub = function (obj, key, value) {
stubs.push({
obj: obj,
key: key,
value: obj[key]
@@ -167,19 +167,15 @@ describe('modulemapper', function () {
expect(modulemapper.getOriginalSymbol(context, 'obj.str')).toBe(context.obj.str);
});
it('Test#017 : should log about deprecated property access', function () {
var origConsoleLog = console.log;
console.log = jasmine.createSpy('console.log');
this.after(function () {
console.log = origConsoleLog;
});
spyOn(console, 'log');
modulemapper.clobbers('cordova/test/testmodule', 'obj', 'Use foo instead');
modulemapper.defaults('cordova/test/testmodule', 'newProp', 'Use foo instead');
modulemapper.mapModules(context);
context.obj.func();
context.obj.func();
expect(console.log.callCount).toBe(1);
expect(console.log).toHaveBeenCalledTimes(1);
context.newProp.func();
context.newProp.func();
expect(console.log.callCount).toBe(2);
expect(console.log).toHaveBeenCalledTimes(2);
});
});
@@ -53,12 +53,13 @@ describe('urlutil', function () {
var baseTag = document.createElement('base');
baseTag.href = rootUrl;
document.head.appendChild(baseTag);
this.after(function () {
try {
expect(urlutil.makeAbsolute('foo?a#b')).toBe(rootUrl + 'foo?a#b');
expect(urlutil.makeAbsolute('foo/b%20ar')).toBe(rootUrl + 'foo/b%20ar');
testRootRelative(rootUrl);
} finally {
document.head.removeChild(baseTag);
});
expect(urlutil.makeAbsolute('foo?a#b')).toBe(rootUrl + 'foo?a#b');
expect(urlutil.makeAbsolute('foo/b%20ar')).toBe(rootUrl + 'foo/b%20ar');
testRootRelative(rootUrl);
}
});

it('Test#005 : can handle scheme-relative URLs', function () {

0 comments on commit 430620d

Please sign in to comment.