From 430620d145fe28ba4f781db736d737906fce4fb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20von=20der=20Gr=C3=BCn?= Date: Wed, 19 Sep 2018 03:06:42 +0200 Subject: [PATCH] Jasmine 3: Replace usage of Spec#after --- src/legacy-exec/test/test/propertyreplacer.js | 17 ++++++++--------- test/test.modulemapper.js | 10 +++------- test/test.urlutil.js | 11 ++++++----- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/legacy-exec/test/test/propertyreplacer.js b/src/legacy-exec/test/test/propertyreplacer.js index 57f7c34ef..89da92a36 100644 --- a/src/legacy-exec/test/test/propertyreplacer.js +++ b/src/legacy-exec/test/test/propertyreplacer.js @@ -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] diff --git a/test/test.modulemapper.js b/test/test.modulemapper.js index 8d867071f..b862a977b 100644 --- a/test/test.modulemapper.js +++ b/test/test.modulemapper.js @@ -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); }); }); diff --git a/test/test.urlutil.js b/test/test.urlutil.js index d21ad4cb0..6b245b1ba 100644 --- a/test/test.urlutil.js +++ b/test/test.urlutil.js @@ -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 () {