Let's write a test for the divs we want; we need two divs, one contains a name, the other a description (Red 2).
// src/components/CardContent.cy.tsximport CardContent from"./CardContent";describe("CardContent", () => {it("should render the card content", () => {cy.mount(<CardContent />);cy.contains("Bjorn Ironside");cy.contains("king of 9th century Sweden"); });});
We make it green by hard-coding the values being tested for (Green 2).
// src/components/CardContent.tsxexportdefaultfunctionCardContent() {return ( <div> <div>Bjorn Ironside</div> <div>king of 9th century Sweden</div> </div> );}
It is becoming obvious we should be passing name and description as props (Red 3).
// src/components/CardContent.cy.tsximport CardContent from"./CardContent";describe("CardContent", () => {it("should render the card content", () => {constname="Bjorn Ironside";constdescription="king of 9th century Sweden";cy.mount(<CardContentname={name} description={description} />);cy.contains(name);cy.contains(description); });});
The test still passes, but the compiler is complaining about the props that don not exist. Let's add those to the component (Green 3). We can also add the types for these props since we know they will both be strings.