Skip to content

Commit c3d1ce0

Browse files
committed
chore: add tests to check for single render
1 parent fd45956 commit c3d1ce0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/__tests__/renderHook.test.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ReactNode } from 'react';
2+
import TestRenderer from 'react-test-renderer';
23
import { renderHook } from '../pure';
34

45
test('gives comitted result', () => {
@@ -94,3 +95,20 @@ test('props type is inferred correctly when initial props is explicitly undefine
9495

9596
expect(result.current).toBe(6);
9697
});
98+
99+
/**
100+
* This test makes sure that calling renderHook does
101+
* not try to detect host component names in any form.
102+
* But since there are numerous methods that could trigger that
103+
* we check the count of renders using React Test Renderers.
104+
*/
105+
test('does render only once', () => {
106+
jest.spyOn(TestRenderer, 'create');
107+
108+
renderHook(() => {
109+
const [state, setState] = React.useState(1);
110+
return [state, setState];
111+
});
112+
113+
expect(TestRenderer.create).toHaveBeenCalledTimes(1);
114+
});

0 commit comments

Comments
 (0)