Skip to content

Latest commit

 

History

History
 
 

testing-lib-example

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Using @testing-library/cypress

You can install and bring Testing library/Cypress to be used in these React component tests. The following example was copied from react-testing-library/example-intro.

it('loads and displays greeting (testing-lib)', () => {
  cy.server()
  cy.route('/greeting', { greeting: 'Hello there' }).as('greet')

  const url = '/greeting'
  mount(<Fetch url={url} />)

  cy.findByText('Load Greeting')
    .wait(1000)
    .click()
  cy.findByRole('heading').should('have.text', 'Hello there')
  cy.findByRole('button').should('be.disabled')
  cy.get('@greet')
    .its('url')
    .should('match', /\/greeting$/)
})

Test image

  • spec.js is an equivalent example test using "plain" Cypress commands.