bahmutov / test-react-hook-form

Component testing for react-hook-form

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

test-react-hook-form

Testing react-hook-form using Cypress and cypress-react-unit-test

See cypress/component/useForm.spec.js

describe('useForm', () => {
  it('submits a form', () => {
    mount(<App onSubmit={cy.stub().as('submit')} />)
    cy.get('input[name=firstname]').type('gleb')
    cy.get('input[name=lastname]').type('b')
    cy.get('input[name=age]').type('10')
    cy.get('form').submit()
    cy.get('@submit').should('have.been.calledWith', {
      firstname: 'gleb',
      lastname: 'b',
      age: '10'
    })
  })
})

Form spec

About

Component testing for react-hook-form


Languages

Language:JavaScript 100.0%