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.tsx
import 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.tsx
export default function CardContent() {
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.tsx
import CardContent from "./CardContent";
describe("CardContent", () => {
it("should render the card content", () => {
const name = "Bjorn Ironside";
const description = "king of 9th century Sweden";
cy.mount(<CardContent name={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.