From d20d304fd1ee917055c4f083c7b1237dc8c26928 Mon Sep 17 00:00:00 2001 From: colbyfayock Date: Mon, 6 Sep 2021 21:10:02 -0400 Subject: [PATCH] fixing jest test --- config/jest.preprocess.js | 2 +- tests/lib/util.test.js | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/config/jest.preprocess.js b/config/jest.preprocess.js index 183a656..9a37e67 100644 --- a/config/jest.preprocess.js +++ b/config/jest.preprocess.js @@ -2,4 +2,4 @@ const babelOptions = { presets: ["babel-preset-gatsby"], }; -module.exports = require("babel-jest").createTransformer(babelOptions); +module.exports = require("babel-jest").default.createTransformer(babelOptions); diff --git a/tests/lib/util.test.js b/tests/lib/util.test.js index 3ded22a..8fdbdef 100644 --- a/tests/lib/util.test.js +++ b/tests/lib/util.test.js @@ -2,34 +2,38 @@ import { isDomAvailable } from "lib/util"; describe("lib::util", () => { describe("isDomAvailable", () => { - let windowSpy; - - beforeEach(() => { - windowSpy = jest.spyOn(global, "window", "get"); - }); + let originalWindow = { ...global.window }; afterEach(() => { - windowSpy.mockRestore(); + Object.defineProperty(global, "window", { + value: originalWindow, + writable: true, + }); }); it("should return true when document create is available", () => { - windowSpy.mockImplementation(() => ({ - document: { - createElement: () => {}, + Object.defineProperty(global, "window", { + value: { + document: { + createElement: () => {}, + }, }, - })); + writable: true, + }); expect(isDomAvailable()).toEqual(true); }); it("should return false with window not available", () => { - windowSpy.mockImplementation(() => undefined); expect(isDomAvailable()).toEqual(false); }); it("should return false with document create not available", () => { - windowSpy.mockImplementation(() => ({ - document: undefined, - })); + Object.defineProperty(global, "window", { + value: { + document: undefined, + }, + writable: true, + }); expect(isDomAvailable()).toEqual(false); }); });