Skip to content

bahmutov/testing-react-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React component testing example

See spec files in src folder.

Example

import React, { useState } from "react"; import { mount } from "cypress-react-unit-test"; function Button(props) { const [text, setText] = useState(""); function handleClick() { setText("PROCEED TO CHECKOUT"); } return <button onClick={handleClick}>{text || props.text}</button>; } describe("Button component", () => { it("it shows the expected text when clicked", () => { mount(<Button text="SUBSCRIBE TO BASIC" />); cy.contains('SUBSCRIBE TO BASIC') .click() .should('have.text', 'PROCEED TO CHECKOUT') }); });

Button spec

About

Testing React component example

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published