New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide mechanism for accessing the page title #402
Comments
This works for me: test("test", async () => {
const Foo = () => (
<>
<Helmet>
<title>foo</title>
</Helmet>
<div>Hello</div>
</>
);
render(<Foo />);
await wait(() => expect(document.title).toEqual("foo"));
}); |
This also works: await waitForDomChange()
expect(document.title).toEqual("foo") And actually if you're not checking for it('should add title and meta tags to <head>', async () => {
render(<MetaDataOpenGraph {...metadata} routeChanged={false} />)
await waitForDomChange()
expect(document.querySelector('head')).toMatchSnapshot()
}) |
A note from the future, this seems to be the updated API: it('renders the login page title', async () => {
await waitFor(() => expect(document.title).toBe('Company Name - Login'));
}); A note for Next JS users, this doesn't seem to work with the |
Describe the feature you'd like:
Similar to this guy who has yet to receive an answer, I'm looking to do the exact same thing (i.e., test dynamic changes to the page title).
Suggested implementation:
Describe alternatives you've considered:
I tried just testing
expect(document.title).toEqual('something')
or evenrequestAnimationFrame
before testing the title, which is what Helmet does for their tests, but no 🎲 .Teachability, Documentation, Adoption, Migration Strategy:
@testing-library
paradigms.The text was updated successfully, but these errors were encountered: