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

Incompatibility with new testing-library/user-event release #190

Closed
pcafstockf opened this issue Mar 22, 2021 · 4 comments
Closed

Incompatibility with new testing-library/user-event release #190

pcafstockf opened this issue Mar 22, 2021 · 4 comments

Comments

@pcafstockf
Copy link

The tests for my angular app make many calls to userEvent.type in testing-library/user-event.

With the new release of testing-library/user-event, these tests (which were passing), now break, and the cause seems to be that angular is no longer detecting changes triggered by typing.
This is not to surprising given the changes described in this user-event PR.

Indeed, rolling back to the previous version of userEvent results in successful tests again.

I'm happy to do more research/debugging, but need a little guidance...
It's not clear to me how the angular-testing-library has been detecting the changes triggered by the previous userEvent.type implementation. If I understood that mechanism better, it might help me provide more information about the current incompatibility.

Thoughts? Suggestions?

@timdeschryver
Copy link
Member

timdeschryver commented Mar 22, 2021

Hi, thanks for opening this issue.
The change detection is triggered by configuring dom testing library here.

The new type implemention should use this config.

I can also take a look at it, but it will take a few days.

@pcafstockf
Copy link
Author

That was exactly what I needed. Thank you!

Closing this issue, as I was able to determine it had nothing to do with any testing-library project.

A 3rd party component (which uses setTimeout heavily), just happened to work because of the way userEvent.type had been implemented.

I was able to use the config mechanism that you pointed out, to write my own wrapper to keep the 3rd party component happy (and even clean up some hacks I had put in my tests to accommodate that component).
:-)

@timdeschryver
Copy link
Member

Is this something that we would also need to fix in this library?
Or was the fix specific to your codebase?

@pcafstockf
Copy link
Author

Lol. That is why I closed, reopened and again closed this issue... I was trying to decide the same thing.

There may be folks that run into a similar problem, but I feel this is ultimately a user land issue, not something for the angular-testing-library.

The 3rd party component (Syncfusion Angular Grid) receives the events from type, but processes them async (sometimes even multiple async calls to process an event). By the time the component has finished its changes, the angular-testing-library has already called detectChanges. I admit to a little hand waving here as I haven't identified the exact difference's and event sequences between a user actually typing (which works) and userEvent.type (which sometimes did not).

My "fix" was to use the asyncWrapper to call setTimeout(r, 0) before angular-testing-library gets a chance to call detectChanges.

On a related note, it would be great if angular-testing-library took a tail patch approach to eventWrapper instead of overwritting (and ignoring) whatever was previously configured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants