Skip to content

Commit

Permalink
Added act() to window resizing in useWindowSize tests. Modified cover…
Browse files Browse the repository at this point in the history
…age command in travis config file.
  • Loading branch information
FellowshipOfThePing committed May 28, 2021
1 parent b61117e commit b658b62
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -12,3 +12,4 @@ install:
- yarn install
script:
- yarn test
- yarn test --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
21 changes: 6 additions & 15 deletions README.md
Expand Up @@ -3,21 +3,12 @@
<p>NPM package containing a set of custom hooks for React.</p>
<br/>
<div align="center">
<a href= "https://www.npmjs.com/package/j-hooks/v/latest">
<img alt="npm" src="https://img.shields.io/npm/v/j-hooks?style=for-the-badge">
</a>
<a href= "https://www.npmjs.com/package/j-hooks/">
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/j-hooks?style=for-the-badge">
</a>
<a href="https://github.com/FellowshipOfThePing/J-Hooks/issues">
<img alt="GitHub issues" src="https://img.shields.io/github/issues/FellowshipOfThePing/J-Hooks?style=for-the-badge">
</a>
<a href="https://github.com/FellowshipOfThePing/J-Hooks/commits/main">
<img alt="GitHub last commit" src="https://img.shields.io/github/last-commit/FellowshipOfThePing/J-Hooks?style=for-the-badge">
</a>
<a href="https://github.com/FellowshipOfThePing/J-Hooks/blob/main/LICENSE">
<img alt="GitHub License" src="https://img.shields.io/github/license/FellowshipOfThePing/J-Hooks?style=for-the-badge">
</a>
<img alt="Build" src="https://travis-ci.com/FellowshipOfThePing/J-Hooks.svg?branch=main">
<img alt="npm" src="https://img.shields.io/npm/v/j-hooks">
<img alt="npm bundle size" src="https://img.shields.io/github/last-commit/FellowshipOfThePing/J-Hooks?style=flat">
<!-- <img alt="GitHub issues" src="https://img.shields.io/github/issues/FellowshipOfThePing/J-Hooks?style=flat"> -->
<img alt="Minified Size" src="https://img.shields.io/bundlephobia/min/j-hooks?style=flat">
<img alt="GitHub License" src="https://img.shields.io/github/license/FellowshipOfThePing/J-Hooks?style=flat">
</br>
</div>
</div>
Expand Down
18 changes: 13 additions & 5 deletions test/useWindowSize.test.js
@@ -1,6 +1,6 @@
import * as React from "react";
import userEvent from "@testing-library/user-event";
import { render, screen, fireEvent } from "@testing-library/react";
import { render, screen, fireEvent, act } from "@testing-library/react";

import { UseWindowSizeExample } from "../examples/useWindowSize.example";

Expand All @@ -25,7 +25,10 @@ describe("useWindowSize", () => {
configurable: true,
value: 150,
});
window.dispatchEvent(new Event("resize"));

act(() => {
window.dispatchEvent(new Event("resize"));
});

expect(window.innerHeight).toBe(150);
expect(width.textContent).toBe(`Width: 1024`);
Expand All @@ -43,7 +46,10 @@ describe("useWindowSize", () => {
configurable: true,
value: 200,
});
window.dispatchEvent(new Event("resize"));

act(() => {
window.dispatchEvent(new Event("resize"));
});

expect(window.innerWidth).toBe(200);
expect(width.textContent).toBe(`Width: 200`);
Expand All @@ -61,15 +67,17 @@ describe("useWindowSize", () => {
configurable: true,
value: 1000,
});
window.dispatchEvent(new Event("resize"));

// Change window height
Object.defineProperty(window, "innerHeight", {
writable: true,
configurable: true,
value: 2000,
});
window.dispatchEvent(new Event("resize"));

act(() => {
window.dispatchEvent(new Event("resize"));
});

expect(window.innerWidth).toBe(1000);
expect(window.innerHeight).toBe(2000);
Expand Down

0 comments on commit b658b62

Please sign in to comment.