-
Notifications
You must be signed in to change notification settings - Fork 660
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
[testing] Helmet.peek() returns previous elements in unit testing #460
Comments
I have the same issue |
I've managed to get this working when using 'https://testing-library.com/docs/react-testing-library/' // Home.js
// Home.test.js
|
@andrastothtw I've found the following setup works: import React from "react"
import {Helmet} from "react-helmet"
import {render} from "enzyme"
Helmet.canUseDOM = false
describe("react-helmet", () => {
afterEach(() => {
Helmet.rewind()
})
it("test 1", () => {
render(<MyApp />)
const helmet = Helmet.peek()
expect(...).toBeTruthy()
})
it("test 2", () => {
render(<MyApp someProp />)
const helmet = Helmet.peek()
expect(...).toBeFalsy()
})
}) From what I can tell, rewind is the reset function you are looking for, but it doesn't work unless you set If it helps, the peek and rewind functions come from react-side-effect, which helped me debug this problem. |
Any update regarding this issue or any workarounds from other engineers? Facing the same issue, the order of unit tests within a test class is changing the values I get from Helmet.peek() as Helmet seems to be keeping track of all the mounted components as part of the earlier tests. |
This is a question/bug report.
How can you 'reset' elements put into
<head>
by Helmet?Helmet.peek()
returns elements from previous tests in the same file? See code below:Code to reproduce
What is the expected behavior?
These two cases should be independent.
Which versions of React and react-helmet...?
react-helmet
: 5.2.1react
: 16.4.1The text was updated successfully, but these errors were encountered: