Skip to content
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

fix: use attachTo in failing tests with jsdom v21.1 #1952

Merged
merged 1 commit into from Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -45,7 +45,7 @@
"eslint-config-prettier": "8.6.0",
"eslint-plugin-prettier": "4.2.1",
"husky": "8.0.3",
"jsdom": "21.0.0",
"jsdom": "21.1.0",
"jsdom-global": "3.0.2",
"lint-staged": "13.1.0",
"prettier": "2.8.3",
Expand Down
26 changes: 13 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions tests/isVisible.spec.ts
Expand Up @@ -50,7 +50,10 @@ describe('isVisible', () => {
}
}
}
const wrapper = mount(Comp)
// TODO: attachTo can be removed when https://github.com/jsdom/jsdom/issues/3502 is fixed
// with jsdom v21.1, getComputedStyle is cached and not updated for elements not in the DOM
// so the test fails (because the element is checked a first time)
const wrapper = mount(Comp, { attachTo: document.body })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I almost wonder if attachTo: document.body should be the default behavior. I wonder if that'd be a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should, I don't know what are the downsides (most testing libs in other ecosystems do attach components right?). As you have more context, do you know why this is not the case in VTU?


expect(wrapper.find('span').isVisible()).toBe(true)
await wrapper.find('button').trigger('click')
Expand All @@ -73,7 +76,10 @@ describe('isVisible', () => {
}
}
}
const wrapper = mount(Comp, {})
// TODO: attachTo can be removed when https://github.com/jsdom/jsdom/issues/3502 is fixed
// with jsdom v21.1, getComputedStyle is cached and not updated for elements not in the DOM
// so the test fails (because the element is checked a first time)
const wrapper = mount(Comp, { attachTo: document.body })

expect(wrapper.find('span').isVisible()).toBe(true)
await wrapper.find('button').trigger('click')
Expand Down