2023-01-10 10:52:30 +00:00
|
|
|
---
|
|
|
|
tags:
|
|
|
|
- javascript
|
|
|
|
- react
|
|
|
|
- testing
|
|
|
|
---
|
|
|
|
|
2024-11-04 14:26:42 +00:00
|
|
|
# Testing basic prop passing in React
|
2023-01-10 10:52:30 +00:00
|
|
|
|
|
|
|
```js
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
|
|
|
|
describe("<CertificateHtml />", () => {
|
|
|
|
it("should render the values passed as props", () => {
|
|
|
|
// Arrange:
|
|
|
|
const stub = {
|
|
|
|
titleOfActivityOrProgramme: "Filming",
|
|
|
|
nameOfDepartment: "The film department",
|
|
|
|
};
|
|
|
|
|
|
|
|
// Act:
|
|
|
|
render(<CertificateHtml {...stub} />);
|
|
|
|
|
|
|
|
// Assert:
|
|
|
|
expect(screen.getByText("Filming")).toBeInTheDocument();
|
|
|
|
expect(screen.getByText("The film department")).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
Or, loop:
|
|
|
|
|
|
|
|
```js
|
|
|
|
for (const entry of Object.values(stub)) {
|
|
|
|
expect(screen.getByText(entry)).toBeInTheDocument();
|
|
|
|
}
|
|
|
|
```
|