Skip to content

Commit

Permalink
Issue #24 Backfill tests for Hooks/useWindow
Browse files Browse the repository at this point in the history
Issue #24 - Add useWindow tests
  • Loading branch information
brandongregoryscott authored Oct 6, 2020
2 parents 049276f + 447f00d commit 566aa47
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 3 deletions.
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module.exports = {
modulePathIgnorePatterns: ["<rootDir>/dist"],
preset: "ts-jest",
roots: ["<rootDir>/src"],
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
setupFilesAfterEnv: [
"<rootDir>/src/setupTests.ts",
// polyfill window.resizeTo
"window-resizeto/polyfill",
],
testEnvironment: "jsdom",
};
58 changes: 58 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"devDependencies": {
"@testing-library/jest-dom": "5.5.0",
"@testing-library/react": "10.0.4",
"@testing-library/react-hooks": "3.4.2",
"@types/faker": "4.1.12",
"@types/jest": "25.1.5",
"@types/node": "13.11.0",
Expand All @@ -35,14 +36,16 @@
"jest-extended": "0.11.5",
"jest-fetch-mock": "3.0.3",
"prettier": "1.19.1",
"react-test-renderer": "16.9.0",
"rimraf": "2.6.2",
"rosie": "2.0.1",
"ts-jest": "25.5.1",
"tslint": "6.1.2",
"tslint-config-prettier": "1.18.0",
"typedoc": "0.17.6",
"typedoc-plugin-markdown": "2.2.17",
"typescript": "3.8.3"
"typescript": "3.8.3",
"window-resizeto": "0.0.2"
},
"files": [
"dist"
Expand Down
33 changes: 32 additions & 1 deletion src/hooks/use-window.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
import { renderHook } from "@testing-library/react-hooks";
import { useWindow } from "./use-window";

const DEFAULT_WIDTH: number = 1024;
const DEFAULT_HEIGHT: number = 768;

describe("useWindow", () => {
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React/issues/24", () => {});
beforeEach(() => {
window.resizeTo(DEFAULT_WIDTH, DEFAULT_HEIGHT);
});

test("returns width and height of window", async () => {
// Arrange & Act
const { result } = renderHook(() => useWindow());

// Assert
expect(result.current.width).toBe(DEFAULT_WIDTH);
expect(result.current.height).toBe(DEFAULT_HEIGHT);
});

test("when window resize event is triggered, returns new width and height of window", async () => {
// Arrange
const { result } = renderHook(() => useWindow());
const windowWidth = DEFAULT_WIDTH + 1;
const windowHeight = DEFAULT_HEIGHT + 1;

// Act
window.resizeTo(windowWidth, windowHeight);

// Assert
expect(result.current.width).toBe(windowWidth);
expect(result.current.height).toBe(windowHeight);
});
});

0 comments on commit 566aa47

Please sign in to comment.