forms.test.tsx 850 B

123456789101112131415161718192021222324252627
  1. import { renderHook } from '@testing-library/react-hooks'
  2. import { useFormHandler } from '../forms'
  3. describe('form hook return values', () => {
  4. const Component = () => useFormHandler({ var: 'val' }, values => { return {} })
  5. const { result } = renderHook(Component)
  6. it('returns correct initial states.', () => {
  7. expect(result.current.values.var).toBe('val')
  8. expect(result.current.errors).toEqual({})
  9. expect(result.current.isSubmitting).toBe(false)
  10. })
  11. it('returns input element properties for valid input names.', () => {
  12. expect(result.current.inputProps('var')).toMatchObject({
  13. name: 'var', id: 'var', onBlur: expect.anything(), onChange: expect.anything()
  14. })
  15. })
  16. it('throws error for invalid input names.', () => {
  17. expect(() => result.current.inputProps('doh!')).toThrow()
  18. })
  19. })
  20. export default true