angular-testing-library icon indicating copy to clipboard operation
angular-testing-library copied to clipboard

Angular Testing Library with combination of HappyDom instead of JSDOM

Open jarekcimoch opened this issue 1 year ago • 4 comments

Hello, I'm using HappyDom instead of JSDOM and I have following issue.

when I do something like await screen.findByText(optionLabel);

observer.observe is not a function TypeError: observer.observe is not a function

at C:\Ohpen\cloned-2\mfes-broker-app-angular\src\node_modules\@testing-library\dom\dist\wait-for.js:96:16

HappyDom is supporting MutationObserver and I guess JSDOM was not out of the box hance some logic there is used. Could it be fixed? Or can I fix it somehow myself?

jarekcimoch avatar Feb 28 '24 15:02 jarekcimoch

We expect the tests to be run in a DOM-like environment. This also means that there's a MutationObserver observer available to react to dom changes. A workaround is to run all tests in a "fake timers context", which doesn't use the observer.

timdeschryver avatar Feb 28 '24 15:02 timdeschryver

@timdeschryver HappyDom is DOM-like env, it has MutiationObserver in place

jarekcimoch avatar Feb 29 '24 08:02 jarekcimoch

@jarekcimoch do you have a reproduction that I can use to test this?

timdeschryver avatar Feb 29 '24 18:02 timdeschryver

https://github.com/capricorn86/happy-dom/issues/1514#issuecomment-2321982309

This error still occurs but there is a workaround in this linked issue. It seems to be related to jest-preset-angular patching the MutationObserver.

matdv avatar Sep 13 '24 11:09 matdv