Answers for "rerender in hooks testing"

1

rerender in hooks testing

import { renderHook, act } from '@testing-library/react-hooks'
import useCounter from './useCounter'

test('should reset counter to updated initial value', () => {
  let initialValue = 0
  const { result, rerender } = renderHook(() => useCounter(initialValue))

  initialValue = 10
  rerender()

  act(() => {
    result.current.reset()
  })

  expect(result.current.count).toBe(10)
})
Posted by: Guest on November-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language