Skip to content

Commit

Permalink
fixing jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
colbyfayock committed Sep 7, 2021
1 parent a7d3614 commit d20d304
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config/jest.preprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
32 changes: 18 additions & 14 deletions tests/lib/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down

0 comments on commit d20d304

Please sign in to comment.