Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test handler functions that use useState hook. #64

Open
canyener opened this issue Jul 19, 2020 · 0 comments
Open

Test handler functions that use useState hook. #64

canyener opened this issue Jul 19, 2020 · 0 comments
Labels
help wanted Extra attention is needed question Further information is requested

Comments

@canyener
Copy link
Owner

 test('useStateTest', () => {
   const setState = jest.fn()
   const useStateMock: any = (initialState: any) => [initialState, setState]
   
  jest.spyOn(React, 'useState').mockImplementation(useStateMock)
  
  //how to trigger useState handler function here?

   const wrapper = mount(<ActivityList activities={fakeActivities} selectActivity={() => { }}/>)
   wrapper.find('Button').first().simulate('click')

   wrapper.update()

   expect(setState).toHaveBeenCalledTimes(1)
 })
@canyener canyener added help wanted Extra attention is needed question Further information is requested labels Jul 19, 2020
@canyener canyener changed the title Test useState hook Test handler functions that use useState hook. Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant