Skip to content

Commit

Permalink
fix: use attachTo in failing tests with jsdom v21.1 (#1952)
Browse files Browse the repository at this point in the history
`attachTo` can be removed when jsdom/jsdom#3502 is fixed
 With jsdom v21.1, `getComputedStyle` is cached and not updated for elements not in the DOM
 so some our tests fail (because the elements are checked a first time)
  • Loading branch information
cexbrayat committed Jan 31, 2023
1 parent b7c131a commit 6c90ff7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
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 })

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

0 comments on commit 6c90ff7

Please sign in to comment.