Skip to content

Commit f42f6d1

Browse files
test: add a test for componentDidUpdate first TDD
1 parent ca288fa commit f42f6d1

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ const Component = props => {
2525
setComponentState('Mounted')
2626
})
2727

28+
useComponentDidUpdate((prevState, prevProps) => {
29+
if (props.data !== prevProps.data) setComponentState('Updated')
30+
})
31+
2832
return (
2933
<div id='component'>
3034
<p>{componentState}</p>
@@ -47,4 +51,13 @@ describe('Test useLifecycleHelpers custom hook', () => {
4751

4852
getByText(/Mounted/i)
4953
})
54+
55+
test('The component should be updated', () => {
56+
const { getByText, rerender } = renderComponent({ data: 'test1' })
57+
58+
const newProps = { data: 'test2' }
59+
rerender(<Component {...newProps} />)
60+
61+
getByText(/Updated/i)
62+
})
5063
})

0 commit comments

Comments
 (0)