Skip to content

Commit 9c1b6a9

Browse files
committed
add test to get test coverage for useSelector to 100%
1 parent 05c0d5b commit 9c1b6a9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

test/hooks/useSelector.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,37 @@ describe('React', () => {
302302

303303
spy.mockRestore()
304304
})
305+
306+
it('re-throws errors from the selector that only occur during rendering', () => {
307+
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})
308+
309+
const Parent = () => {
310+
const count = useSelector(s => s.count)
311+
return <Child parentCount={count} />
312+
}
313+
314+
const Child = ({ parentCount }) => {
315+
const result = useSelector(({ count }) => {
316+
if (parentCount > 0) {
317+
throw new Error()
318+
}
319+
320+
return count + parentCount
321+
})
322+
323+
return <div>{result}</div>
324+
}
325+
326+
rtl.render(
327+
<ProviderMock store={store}>
328+
<Parent />
329+
</ProviderMock>
330+
)
331+
332+
expect(() => store.dispatch({ type: '' })).toThrowError()
333+
334+
spy.mockRestore()
335+
})
305336
})
306337

307338
describe('error handling for invalid arguments', () => {

0 commit comments

Comments
 (0)