eolas/neuron/ddffeb55-a55e-477a-a982-100e3b1a6e7a/Basic_prop_passing_in_React.md

38 lines
717 B
Markdown
Raw Normal View History

2024-10-19 11:00:03 +01:00
---
tags:
- javascript
- react
- testing
---
# Test: Basic prop passing
```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();
}
```