diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index 97943aec..8162472f 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -3,7 +3,7 @@ describe('Env integration', function() { const isBrowser = typeof window !== 'undefined'; beforeEach(function() { - jasmine.getEnv().registerIntegrationMatchers(); + specHelpers.registerIntegrationMatchers(); env = new jasmineUnderTest.Env(); }); diff --git a/spec/core/integration/MatchersSpec.js b/spec/core/integration/MatchersSpec.js index 9e6994fc..f09656cd 100755 --- a/spec/core/integration/MatchersSpec.js +++ b/spec/core/integration/MatchersSpec.js @@ -610,19 +610,13 @@ describe('Matchers (Integration)', function() { }); describe('toHaveClass', function() { - beforeEach(function() { - this.domHelpers = jasmine.getEnv().domHelpers(); - }); - verifyPasses(function(env) { - const domHelpers = jasmine.getEnv().domHelpers(); - const el = domHelpers.createElementWithClassName('foo'); + const el = specHelpers.domHelpers.createElementWithClassName('foo'); env.expect(el).toHaveClass('foo'); }); verifyFails(function(env) { - const domHelpers = jasmine.getEnv().domHelpers(); - const el = domHelpers.createElementWithClassName('foo'); + const el = specHelpers.domHelpers.createElementWithClassName('foo'); env.expect(el).toHaveClass('bar'); }); }); diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index 775c0d2f..32439a3a 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -2,7 +2,7 @@ describe('spec running', function() { let env; beforeEach(function() { - jasmine.getEnv().registerIntegrationMatchers(); + specHelpers.registerIntegrationMatchers(); env = new jasmineUnderTest.Env(); env.configure({ random: false }); }); diff --git a/spec/core/matchers/toHaveClassSpec.js b/spec/core/matchers/toHaveClassSpec.js index 3ad1034a..c997d3f6 100644 --- a/spec/core/matchers/toHaveClassSpec.js +++ b/spec/core/matchers/toHaveClassSpec.js @@ -1,12 +1,8 @@ describe('toHaveClass', function() { - beforeEach(function() { - this.domHelpers = jasmine.getEnv().domHelpers(); - }); - it('fails for a DOM element that lacks the expected class', function() { const matcher = jasmineUnderTest.matchers.toHaveClass(), result = matcher.compare( - this.domHelpers.createElementWithClassName(''), + specHelpers.domHelpers.createElementWithClassName(''), 'foo' ); @@ -15,7 +11,7 @@ describe('toHaveClass', function() { it('passes for a DOM element that has the expected class', function() { const matcher = jasmineUnderTest.matchers.toHaveClass(), - el = this.domHelpers.createElementWithClassName('foo bar baz'); + el = specHelpers.domHelpers.createElementWithClassName('foo bar baz'); expect(matcher.compare(el, 'foo').pass).toBe(true); expect(matcher.compare(el, 'bar').pass).toBe(true); @@ -24,7 +20,7 @@ describe('toHaveClass', function() { it('fails for a DOM element that only has other classes', function() { const matcher = jasmineUnderTest.matchers.toHaveClass(), - el = this.domHelpers.createElementWithClassName('foo bar'); + el = specHelpers.domHelpers.createElementWithClassName('foo bar'); expect(matcher.compare(el, 'fo').pass).toBe(false); }); @@ -42,7 +38,7 @@ describe('toHaveClass', function() { matcher.compare(undefined, 'foo'); }).toThrowError('undefined is not a DOM element'); - const textNode = this.domHelpers.document.createTextNode(''); + const textNode = specHelpers.domHelpers.document.createTextNode(''); expect(function() { matcher.compare(textNode, 'foo'); }).toThrowError('HTMLNode is not a DOM element'); diff --git a/spec/helpers/BrowserFlags.js b/spec/helpers/BrowserFlags.js index be5a7387..eb4f3c6b 100644 --- a/spec/helpers/BrowserFlags.js +++ b/spec/helpers/BrowserFlags.js @@ -1,4 +1,4 @@ -(function(env) { +(function() { function browserVersion(matchFn) { const userAgent = jasmine.getGlobal().navigator.userAgent; if (!userAgent) { @@ -10,7 +10,7 @@ return match ? parseFloat(match[1]) : void 0; } - env.firefoxVersion = browserVersion(function(userAgent) { + specHelpers.firefoxVersion = browserVersion(function(userAgent) { return /Firefox\/([0-9]{0,})/.exec(userAgent); }); -})(jasmine.getEnv()); +})(); diff --git a/spec/helpers/domHelpers.js b/spec/helpers/domHelpers.js index 9cdb349a..a519428b 100644 --- a/spec/helpers/domHelpers.js +++ b/spec/helpers/domHelpers.js @@ -1,24 +1,20 @@ -(function(env) { - function domHelpers() { - let doc; +(function() { + let doc; - if (typeof document !== 'undefined') { - doc = document; - } else { - const JSDOM = require('jsdom').JSDOM; - const dom = new JSDOM(); - doc = dom.window.document; - } - - return { - document: doc, - createElementWithClassName: function(className) { - const el = this.document.createElement('div'); - el.className = className; - return el; - } - }; + if (typeof document !== 'undefined') { + doc = document; + } else { + const JSDOM = require('jsdom').JSDOM; + const dom = new JSDOM(); + doc = dom.window.document; } - env.domHelpers = domHelpers; -})(jasmine.getEnv()); + specHelpers.domHelpers = { + document: doc, + createElementWithClassName(className) { + const el = this.document.createElement('div'); + el.className = className; + return el; + } + }; +})(); diff --git a/spec/helpers/init.js b/spec/helpers/init.js new file mode 100644 index 00000000..6b5afcda --- /dev/null +++ b/spec/helpers/init.js @@ -0,0 +1 @@ +globalThis.specHelpers = {}; diff --git a/spec/helpers/integrationMatchers.js b/spec/helpers/integrationMatchers.js index fd80b83c..aea7cc4d 100644 --- a/spec/helpers/integrationMatchers.js +++ b/spec/helpers/integrationMatchers.js @@ -1,5 +1,5 @@ -(function(env) { - env.registerIntegrationMatchers = function() { +(function() { + specHelpers.registerIntegrationMatchers = function() { jasmine.addMatchers({ toHaveFailedExpectationsForRunnable: function() { return { @@ -51,4 +51,4 @@ } }); }; -})(jasmine.getEnv()); +})(); diff --git a/spec/html/PrettyPrintHtmlSpec.js b/spec/html/PrettyPrintHtmlSpec.js index a5e67b28..e667da8f 100644 --- a/spec/html/PrettyPrintHtmlSpec.js +++ b/spec/html/PrettyPrintHtmlSpec.js @@ -22,7 +22,7 @@ describe('PrettyPrinter (HTML Dependent)', function() { }); it("should print Firefox's wrapped native objects correctly", function() { - if (jasmine.getEnv().firefoxVersion) { + if (specHelpers.firefoxVersion) { const pp = jasmineUnderTest.makePrettyPrinter(); let err; try { diff --git a/spec/support/jasmine-browser.js b/spec/support/jasmine-browser.js index f86dfe3e..39969c59 100644 --- a/spec/support/jasmine-browser.js +++ b/spec/support/jasmine-browser.js @@ -18,6 +18,7 @@ module.exports = { specDir: 'spec', specFiles: ['**/*[Ss]pec.js', '!npmPackage/**/*'], helpers: [ + 'helpers/init.js', 'helpers/generator.js', 'helpers/BrowserFlags.js', 'helpers/domHelpers.js', diff --git a/spec/support/jasmine.json b/spec/support/jasmine.json index f24ab080..89240a27 100644 --- a/spec/support/jasmine.json +++ b/spec/support/jasmine.json @@ -5,6 +5,7 @@ "npmPackage/**/*[Ss]pec.js" ], "helpers": [ + "helpers/init.js", "helpers/domHelpers.js", "helpers/integrationMatchers.js", "helpers/overrideConsoleLogForCircleCi.js",