-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ handle hooks setState with function
- Loading branch information
1 parent
ffa2b33
commit 2022724
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
packages/component-test-utils-react/src/__tests__/react-useState.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const {shallow} = require('../shallow'); | ||
const React = require('react'); | ||
|
||
describe('shallow - react useState', () => { | ||
const Component = () => { | ||
const [state, setState] = React.useState('initialState'); | ||
const handleClick = () => { | ||
setState(prevState => `${prevState}+1`); | ||
}; | ||
|
||
return <button type="button" onClick={handleClick}>{state}</button>; | ||
}; | ||
|
||
it('should return the initialState correctly', () => { | ||
const cmp = shallow(<Component/>); | ||
|
||
expect(cmp.html()).toBe('<button type="button" onClick="[handleClick]">initialState</button>'); | ||
}); | ||
|
||
it('should update the state when cllicking on the button', () => { | ||
const cmp = shallow(<Component/>); | ||
|
||
cmp.dispatchEvent('click'); | ||
|
||
expect(cmp.html()).toBe('<button type="button" onClick="[handleClick]">initialState+1</button>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters