testing-library / angular-testing-library

🐙 Simple and complete Angular testing utilities that encourage good testing practices
https://testing-library.com/angular
MIT License
717 stars 91 forks source link

Angular Testing Library with combination of HappyDom instead of JSDOM #440

Open jarekcimoch opened 8 months ago

jarekcimoch commented 8 months ago

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?

timdeschryver commented 8 months ago

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.

jarekcimoch commented 8 months ago

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

timdeschryver commented 8 months ago

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

matdv commented 2 months ago

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.