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')
});
});