-
Notifications
You must be signed in to change notification settings - Fork 668
Rendered dom not being removed from document after each test when attachToDocument is true #1185
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
Comments
We've been able to work around this temporarily by doing similar to the following: const App = Vue.extend({
template: '<div><button>Button</button></div>',
destroyed() {
// Hack to remove DOM from document as vue-test-utils leaves
// the rendered DOM in document after each test, when
// mounting option `attachToDocument` is true.
// Requires each test to call wrapper.vm.$destroy() when done
if (this.$el && this.$el.parentNode && this.$el.parentNode.removeChild) {
this.$el.parentNode.removeChild(this.$el)
}
}
}) and then calling |
You need to use the const wrapper = mount(TestComponent, {
attachToDocument: true
})
wrapper.destroy() We should add |
Yeah, I did't know about the Docs update would be a great help... and maybe mentioning that the DOM+vm sticks around if not destroyed, which would over time - during a test suite - waste memory footprint. |
@eddyerburgh One side note....
Hence for testing functional components, there is no way to remove the DOM generated by a functional component.
|
I am just now using |
Version
1.0.0-beta.29
Reproduction link
https://codesandbox.io/s/y006o3zxqz
Steps to reproduce
Run the sanbox, and view the test results.
The second test fails, as it finds two buttons in the DOM.
What is expected?
The previous test's DOM to be removed from the document.
What is actually happening?
the old test DOM persists in the document.
When using
document.querySelectorAll(...)
inside an app, and testing various scenarios, the old APPs DOM is not being removed from the JSDOM document whenmountToDocument: true
is set during mount, causing unexpected results in the tests.The text was updated successfully, but these errors were encountered: