-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #24 Backfill tests for Hooks/useWindow
Issue #24 - Add useWindow tests
- Loading branch information
Showing
4 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |