Test custom async hooks
- Dominant language
- JavaScript
- Stars
- 19.8k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
I use Enzyme version 3.8.0.
```
// functional component
const UsersList = ({ onItemSelected, }) => {
// async service fetch hooks
const url = 'service-url';
const { error, loading, data, } = useService(Service, url, {
amount: 0,
});
return (
{
data.map(user => (
))
}
);
};
```
My useService make an async call to get user list data.
**Test :**
```
jest.mock('axios');
it('Should Mount Component & Display Data', async () => {
// mock result
axiosMock.get.mockResolvedValue(UserListMock);
// mount component
const wrapper = mount();
// wait to have data
await expect(wrapper.state().data).to.not.be.null;
// test
expect(wrapper.find('h2').first().text()).toEqual('Mock Title');
});
```
**But I have this error :**
`ReactWrapper::state() can only be called on class components`
Contributor guide
Assessment
This issue has not been assessed yet.