Skip to content

Commit 7f40977

Browse files
committed
[pkg] Upgrade to @testing-library/react-hooks
1 parent e64d852 commit 7f40977

File tree

10 files changed

+54
-57
lines changed

10 files changed

+54
-57
lines changed

docs/api/makeRenderRestHook.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function makeRenderRestHook(makeProvider: ProviderType): RenderRestHookFunction;
77
```
88

99
`makeRenderRestHook()` is useful to test hooks that rely on the `rest-hooks`. It creates a renderRestHook()
10-
function that mirrors [react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library)'s [renderHook()](https://github.com/mpeyper/react-hooks-testing-library#renderhookcallback-options) but does so with a `<Suspense/>` boundary
10+
function that mirrors [@testing-library/react-hooks](https://github.com/testing-library/react-hooks-testing-library)'s [renderHook()](https://react-hooks-testing-library.com/reference/api#renderhook-options) but does so with a `<Suspense/>` boundary
1111
as well as in a `<Provider />` context.
1212

1313
## Arguments
@@ -85,7 +85,7 @@ Cleans up all managers used in tests. Should be run in `afterEach()` to ensure e
8585
- `rerender` (`function([newProps])`) - function to rerender the test component including any hooks called in the `callback` function. If `newProps` are passed, the will replace the `initialProps` passed the the `callback` function for future renders.
8686
- `unmount` (`function()`) - function to unmount the test component, commonly used to trigger cleanup effects for `useEffect` hooks.
8787

88-
[react-hooks-testing-library reference](https://github.com/mpeyper/react-hooks-testing-library/blob/master/README.md#returns)
88+
[@testing-library/react-hooks reference](https://react-hooks-testing-library.com/reference/api#renderhook-result)
8989

9090
## Example
9191

docs/guides/unit-testing-hooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ composable functions. This makes testing component behavior potentially much
77
easier. But how does this work if you want to use hooks from `rest-hooks`?
88

99
We have provided some simple utilities to reduce boilerplate for unit tests
10-
that are wrappers around [react-hooks-testing-library](https://github.com/mpeyper/react-hooks-testing-library)'s [renderHook()](https://github.com/mpeyper/react-hooks-testing-library#renderhookcallback-options).
10+
that are wrappers around [@testing-library/react-hooks](https://github.com/testing-library/react-hooks-testing-library)'s [renderHook()](https://react-hooks-testing-library.com/reference/api#renderhook-options).
1111

1212
We want a `renderRestHook()` function that renders in the context of both
1313
a `Provider` and `Suspense` boundary.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"@anansi/eslint-config": "^0.6.5",
8181
"@babel/cli": "^7.5.5",
8282
"@babel/core": "^7.5.5",
83+
"@testing-library/react-hooks": "^1.1.0",
8384
"@types/jest": "^24.0.17",
8485
"@types/lodash": "^4.14.136",
8586
"@types/nock": "^10.0.3",
@@ -102,7 +103,7 @@
102103
"prettier-eslint-cli": "^5.0.0",
103104
"react": "16.8.6",
104105
"react-dom": "16.8.6",
105-
"react-hooks-testing-library": "^0.4.1",
106+
"react-test-renderer": "^16.8.6",
106107
"react-testing-library": "^6.1.2",
107108
"rollup": "^1.17.0",
108109
"rollup-plugin-babel": "^4.3.3",

src/react-integration/__tests__/hooks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Suspense, useEffect } from 'react';
2-
import { render, wait } from 'react-testing-library';
3-
import { cleanup, renderHook } from 'react-hooks-testing-library';
2+
import { render, cleanup } from 'react-testing-library';
3+
import { renderHook } from '@testing-library/react-hooks';
44
import nock from 'nock';
55
import { normalize } from '../../resource';
66

src/react-integration/__tests__/integration.tsx

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import { cleanup } from 'react-hooks-testing-library';
32
import nock from 'nock';
43

54
import {
@@ -14,8 +13,14 @@ import {
1413
makeExternalCacheProvider,
1514
} from '../../test/providers';
1615

16+
function onError(e: any) {
17+
e.preventDefault();
18+
}
19+
beforeEach(() => {
20+
window.addEventListener('error', onError);
21+
});
1722
afterEach(() => {
18-
cleanup();
23+
window.removeEventListener('error', onError);
1924
});
2025

2126
for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
@@ -66,16 +71,6 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
6671

6772
let renderRestHook: ReturnType<typeof makeRenderRestHook>;
6873

69-
function onError(e: any) {
70-
e.preventDefault();
71-
}
72-
beforeEach(() => {
73-
window.addEventListener('error', onError);
74-
});
75-
afterEach(() => {
76-
window.removeEventListener('error', onError);
77-
});
78-
7974
beforeEach(() => {
8075
nock('http://test.com')
8176
.get(`/article-cooler/${payload.id}`)
@@ -131,7 +126,7 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
131126
});
132127

133128
it('should throw when retrieving an empty string', async () => {
134-
const { result, waitForNextUpdate } = renderRestHook(() => {
129+
const { result } = renderRestHook(() => {
135130
return useFetcher(CoolerArticleResource.detailShape());
136131
});
137132

@@ -141,7 +136,7 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
141136
});
142137

143138
it('should not throw on delete', async () => {
144-
const { result, waitForNextUpdate } = renderRestHook(() => {
139+
const { result } = renderRestHook(() => {
145140
return [
146141
useFetcher(CoolerArticleResource.deleteShape()),
147142
useFetcher(ArticleResource.deleteShape()),
@@ -204,7 +199,7 @@ for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
204199

205200
it('should not suspend with no params to useResource()', async () => {
206201
let article: any;
207-
const { result, waitForNextUpdate } = renderRestHook(() => {
202+
const { result } = renderRestHook(() => {
208203
article = useResource(CoolerArticleResource.detailShape(), null);
209204
return 'done';
210205
});

src/react-integration/__tests__/subscriptions.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
2-
import { cleanup } from 'react-hooks-testing-library';
3-
import { renderHook } from 'react-hooks-testing-library';
2+
import { renderHook } from '@testing-library/react-hooks';
43

54
import nock from 'nock';
65

@@ -13,8 +12,6 @@ import {
1312
} from '../../test/providers';
1413
import { DispatchContext } from '../context';
1514

16-
afterEach(cleanup);
17-
1815
for (const makeProvider of [makeCacheProvider, makeExternalCacheProvider]) {
1916
describe(`${makeProvider.name} with subscriptions`, () => {
2017
const articlePayload = {

src/react-integration/provider/__tests__/middleware.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
// eslint-disable-next-line @typescript-eslint/camelcase
33
import { unstable_scheduleCallback } from 'scheduler';
4-
import { cleanup, renderHook, act } from 'react-hooks-testing-library';
4+
import { renderHook, act } from '@testing-library/react-hooks';
55
import createEnhancedReducerHook from '../middleware';
66
import { MiddlewareAPI } from '../../../types';
77

@@ -14,7 +14,6 @@ beforeEach(() => {
1414
afterEach(() => {
1515
window.removeEventListener('error', ignoreError);
1616
});
17-
afterEach(cleanup);
1817

1918
describe('createEnhancedReducerHook', () => {
2019
const makeTestActionMiddleware = (test: Function) => () => {

src/test/makeRenderRestHook.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { RenderOptions } from 'react-testing-library';
3-
import { renderHook } from 'react-hooks-testing-library';
3+
import { renderHook } from '@testing-library/react-hooks';
44

55
import { MockNetworkManager } from './managers';
66
import mockInitialState, { Fixture } from './mockState';

src/test/managers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { act } from 'react-hooks-testing-library';
1+
import { act } from '@testing-library/react-hooks';
22

33
import { NetworkManager, FetchAction, ReceiveAction } from '..';
44

yarn.lock

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,15 @@
12771277
resolved "https://registry.yarnpkg.com/@sheerun/mutationobserver-shim/-/mutationobserver-shim-0.3.2.tgz#8013f2af54a2b7d735f71560ff360d3a8176a87b"
12781278
integrity sha512-vTCdPp/T/Q3oSqwHmZ5Kpa9oI7iLtGl3RQaA/NyLHikvcrPxACkkKVr/XzkSPJWXHRhKGzVvb0urJsbMlRxi1Q==
12791279

1280+
"@testing-library/react-hooks@^1.1.0":
1281+
version "1.1.0"
1282+
resolved "https://registry.yarnpkg.com/@testing-library/react-hooks/-/react-hooks-1.1.0.tgz#14b6b5c7c3d0e2cb3e55e9cbb248b44321641c64"
1283+
integrity sha512-piE/ceQoNf134FFVXBABDbttBJ8eLPD4eg7zIciVJv92RyvoIsBHCvvG8Vd4IG5pyuWYrkLsZTO8ucZBwa4twA==
1284+
dependencies:
1285+
"@babel/runtime" "^7.4.2"
1286+
"@types/react" "^16.8.22"
1287+
"@types/react-test-renderer" "^16.8.2"
1288+
12801289
"@types/babel__core@^7.1.0":
12811290
version "7.1.0"
12821291
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.0.tgz#710f2487dda4dcfd010ca6abb2b4dc7394365c51"
@@ -1413,10 +1422,17 @@
14131422
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.0.tgz#4c48fed958d6dcf9487195a0ef6456d5f6e0163a"
14141423
integrity sha512-eItQyV43bj4rR3JPV0Skpl1SncRCdziTEK9/v8VwXmV6d/qOUO8/EuWeHBbCZcsfSHfzI5UyMJLCSXtxxznyZg==
14151424

1416-
"@types/react@^16.8.24":
1417-
version "16.8.24"
1418-
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.8.24.tgz#8d1ea1fcbfa214220da3d3c04e506f1077b0deac"
1419-
integrity sha512-VpFHUoD37YNY2+lr/+c7qL/tZsIU/bKuskUF3tmGUArbxIcQdb5j3zvo4cuuzu2A6UaVmVn7sJ4PgWYNFEBGzg==
1425+
"@types/react-test-renderer@^16.8.2":
1426+
version "16.9.0"
1427+
resolved "https://registry.yarnpkg.com/@types/react-test-renderer/-/react-test-renderer-16.9.0.tgz#d60f530ecf4c906721511603cca711b4fa830d41"
1428+
integrity sha512-bN5EyjtuTY35xX7N5j0KP1vg5MpUXHpFTX6tGsqkNOthjNvet4VQOYRxFh+NT5cDSJrATmAFK9NLeYZ4mp/o0Q==
1429+
dependencies:
1430+
"@types/react" "*"
1431+
1432+
"@types/react@*", "@types/react@^16.8.22", "@types/react@^16.8.24":
1433+
version "16.9.1"
1434+
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.1.tgz#862c83b4c9d5cd116e42fd9a4f3694843cd2c051"
1435+
integrity sha512-jGM2x8F7m7/r+81N/BOaUKVwbC5Cdw6ExlWEUpr77XPwVeNvAppnPEnMMLMfxRDYL8FPEX8MHjwtD2NQMJ0yyQ==
14201436
dependencies:
14211437
"@types/prop-types" "*"
14221438
csstype "^2.2.0"
@@ -3121,16 +3137,6 @@ doctrine@^3.0.0:
31213137
dependencies:
31223138
esutils "^2.0.2"
31233139

3124-
dom-testing-library@^3.18.2:
3125-
version "3.18.2"
3126-
resolved "https://registry.yarnpkg.com/dom-testing-library/-/dom-testing-library-3.18.2.tgz#07d65166743ad3299b7bee5b488e9622c31241bc"
3127-
integrity sha512-+nYUgGhHarrCY8kLVmyHlgM+IGwBXXrYsWIJB6vpAx2ne9WFgKfwMGcOkkTKQhuAro0sP6RIuRGfm5NF3+ccmQ==
3128-
dependencies:
3129-
"@babel/runtime" "^7.3.4"
3130-
"@sheerun/mutationobserver-shim" "^0.3.2"
3131-
pretty-format "^24.5.0"
3132-
wait-for-expect "^1.1.0"
3133-
31343140
dom-testing-library@^3.19.0:
31353141
version "3.19.1"
31363142
resolved "https://registry.yarnpkg.com/dom-testing-library/-/dom-testing-library-3.19.1.tgz#ccde9044cacd6d95e5e5629b9cdd2f4de3ea5e1d"
@@ -6565,26 +6571,25 @@ react-dom@16.8.6:
65656571
prop-types "^15.6.2"
65666572
scheduler "^0.13.6"
65676573

6568-
react-hooks-testing-library@^0.4.1:
6569-
version "0.4.1"
6570-
resolved "https://registry.yarnpkg.com/react-hooks-testing-library/-/react-hooks-testing-library-0.4.1.tgz#481b960d647d3cc7c8bbaf410014daa8ce0b1360"
6571-
integrity sha512-ogmlyW7ycZe3+HIk1Y+FUV5ExpZwLi/RlF1qGLLbTkUdaAsGgp9fSF+wFNWi2KNKBTWG0FkkqOrLkcwq0z3ebQ==
6572-
dependencies:
6573-
"@babel/runtime" "^7.4.2"
6574-
react-testing-library "^6.0.3"
6575-
65766574
react-is@^16.8.1, react-is@^16.8.4:
65776575
version "16.8.4"
65786576
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.4.tgz#90f336a68c3a29a096a3d648ab80e87ec61482a2"
65796577
integrity sha512-PVadd+WaUDOAciICm/J1waJaSvgq+4rHE/K70j0PFqKhkTBsPv/82UGQJNXAngz1fOQLLxI6z1sEDmJDQhCTAA==
65806578

6581-
react-testing-library@^6.0.3:
6582-
version "6.0.3"
6583-
resolved "https://registry.yarnpkg.com/react-testing-library/-/react-testing-library-6.0.3.tgz#8b5d276a353c17ce4f7486015bb7a1c8827c442c"
6584-
integrity sha512-tN0A6nywSOoL8kriqru3rSdw31PxuquL7xnW6xBI0aTNw0VO3kZQtaEa0npUH9dX0MIsSunB0nbElRrc4VtAzw==
6579+
react-is@^16.8.6:
6580+
version "16.8.6"
6581+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16"
6582+
integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA==
6583+
6584+
react-test-renderer@^16.8.6:
6585+
version "16.8.6"
6586+
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.8.6.tgz#188d8029b8c39c786f998aa3efd3ffe7642d5ba1"
6587+
integrity sha512-H2srzU5IWYT6cZXof6AhUcx/wEyJddQ8l7cLM/F7gDXYyPr4oq+vCIxJYXVGhId1J706sqziAjuOEjyNkfgoEw==
65856588
dependencies:
6586-
"@babel/runtime" "^7.4.2"
6587-
dom-testing-library "^3.18.2"
6589+
object-assign "^4.1.1"
6590+
prop-types "^15.6.2"
6591+
react-is "^16.8.6"
6592+
scheduler "^0.13.6"
65886593

65896594
react-testing-library@^6.1.2:
65906595
version "6.1.2"

0 commit comments

Comments
 (0)