Replace jsdom with happy-dom testing environment to enable Modal tests (#461)#545
Conversation
|
The problem is in See: jsdom/jsdom#3299 |
|
Because of missing support for It ready for review. A mentioned guys from Spirit team for inspiration as their Modal is missing tests. |
adamkudrna
left a comment
There was a problem hiding this comment.
As far as I can understand what's going on, a ✅ for me.
| ], | ||
| [ | ||
| { size: 'small' }, | ||
| (rootElement) => expect(within(rootElement).getByRole('presentation')).toHaveClass('isRootSizeSmall'), |
There was a problem hiding this comment.
It could still be getByRole('dialog'), couldn't it?
| // While <dialog> component uses built-in browser dialog functionality for closing the dialog, we preserve this | ||
| // functionality due to lack of support for <dialog> in jsdom and happy-dom testing environments. |
There was a problem hiding this comment.
Do we have any jsdom/happy-dom issues to link to so we can remove this in future?
There was a problem hiding this comment.
We don't. This is not only think that lacks support. I would write more about it later or I would speak about it on Monday.
b7ca42f to
ec8d690
Compare
9151d36 to
c2efcfb
Compare
| assertFocus(el, true); | ||
| }); | ||
|
|
||
| it('traps focus', async () => { |
There was a problem hiding this comment.
HTML dialog handles focus trap manually, so there is no need to test it. What more, it does not work in testing environment as it is not implemented.
a9e659c to
c899062
Compare
…` tests (#461) `happy-dom` is used due to missing HtmlDialogElement support in `jest`. Just to mention, `happy-dom` provides partial support for dialog element, so not all test can be implemented.
c899062 to
41ff8c2
Compare
jsdom with happy-dom testing environment to enable Modal tests (#461)jsdom with happy-dom testing environment to enable Modal tests (#461)
This is work-in-progress pull request!
I've replacedjsdomwithhappy-domtesting environment and with little changes (typically because of use of incorrect jest functions ) andModaltests with<dialog>works almost as expected. But for some reason, there are 4 tests inGrid.test.jsxthat does not work. TBH, I don't know why.~~I debbuged test functions, respectively
toHaveStylewhich is part ofnode_modules/@testing-library/jest-dom/dist/matchers-342a062d.js.toHaveStyleinternally usesisSubsetfunction`. I edited function to be able to debug it step-by-step:And for some reason, not all CSS properties are part of computed styles (variablev) and that's the reason why the tests fails.Can anybody look at it? Can we discuss if this is the right way? Because withouthappy-dom, we won't be able to test ourModalcomponent which is problem guys from LMC's Spirit Design System encountered. (cc @adamkudrna @crishpeen @literat).If we want to have Modal tested, we either skip those tests for rowGap and columnGap or we can test it different way, for example using.outerHTML.contains(<css>). It is not perfect nor good, but it works at least.