4

I'm using react-helmet and change the documents page title depending on some conditions.

How can I test that behaviour with react-testing-library?

I tried something like

const { debug } = render(<TitleChangingComponent title="Test" />, {
    container: document.head,
});
debug();

But it just shows me an empty in the debug output. Additionally I'm not 100% sure if this is related to react-testing-library in general or jsdom (I'm using Jest for my tests).

LongFlick
  • 1,129
  • 1
  • 12
  • 21

1 Answers1

-2

I wouldn't use react-testing-library for this.

I would test this in an E2E test e.g. with Cypress.

cy.title().should('eq', '<your-title>')

Opinionated:

It is best practice to test your components and pure logic using unit tests and side effects as well as user interaction using end to end tests.

J. Hesters
  • 13,117
  • 31
  • 133
  • 249