Skip to content

Commit 9b45e63

Browse files
author
Tom Lienard
authored
chore: use @testing-library/react for renderHook (#828)
* chore: use for * fix: update lockfile * fix: react throw errors
1 parent 2a1a108 commit 9b45e63

File tree

8 files changed

+313
-320
lines changed

8 files changed

+313
-320
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"@rollup/plugin-node-resolve": "13.3.0",
1919
"@testing-library/jest-dom": "5.16.4",
2020
"@testing-library/react": "13.3.0",
21-
"@testing-library/react-hooks": "8.0.0",
2221
"@types/jest": "28.1.1",
2322
"@types/node": "17.0.31",
2423
"@types/prop-types": "15.7.5",

packages/use-gtm/src/__tests__/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { fireEvent } from '@testing-library/react'
2-
import { renderHook } from '@testing-library/react-hooks'
1+
import { fireEvent, renderHook } from '@testing-library/react'
32
import mockdate from 'mockdate'
43
import { ReactNode } from 'react'
54
import GTMProvider, { SendGTM, useGTM } from '..'
@@ -48,10 +47,18 @@ describe('GTM hook', () => {
4847
})
4948

5049
it('useGTM should not be defined without GTMProvider', () => {
51-
const { result } = renderHook(() => useGTM())
52-
expect(() => {
53-
expect(result.current).toBe(undefined)
54-
}).toThrow(Error('useGTM must be used within a GTMProvider'))
50+
const orignalConsoleError = console.error
51+
console.error = jest.fn
52+
53+
try {
54+
renderHook(() => useGTM())
55+
} catch (error) {
56+
expect((error as Error)?.message).toBe(
57+
'useGTM must be used within a GTMProvider',
58+
)
59+
}
60+
61+
console.error = orignalConsoleError
5562
})
5663

5764
it('Provider should call onLoadError if script fail to load', () => {

0 commit comments

Comments
 (0)