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
bug(MatSnackBarHarness): Testing a snack bar with a duration #19290
Comments
I can confirm this is still an issue with
|
I am having this issue as well, any ideas as to a work around? |
My "workaround" involves using a whole test library (that I wrote). It runs test in the For an example that uses |
The issue is still present with:
Trying to retrieve the harness with
Also, as described ersimont, the test is still hanging for the duration the snackbar is open. If it's not planned to fix it any time soon, it would be nice to indicate in the doc that this Harness is broken to avoid people wasting time on it, and wondering why their test is failing (what I experimented this morning). |
The issue is still present with Angular v15 and the MDC-based Snack Bar. |
I had the same issue on Angular 14.2.12 and Material 14.2.7. Getting the error:
when using |
It still had the same issue on Angular 16.2.12 and Material 16.2.14, and I got a workaround to fix it by simply wrap harness code block into
|
I ran into this problem recently and I've come up with a solution which I believe is easy and fast. Instead of using a harness to get the snackbar, just spy on it instead.
You can then test the snackbar opening with specific values in a few ways
You might also have some success experimenting with |
Reproduction
https://stackblitz.com/edit/components-issue-v9512z?file=src%2Fapp%2Fexample-test.spec.ts
Steps to reproduce:
await harness.getMessage()
a snack bar that was opened with aduration
. You can see this simply by following the link above, which will run that automatically.Expected Behavior
The harness returns the message in the snack bar.
Actual Behavior
The test hangs for the duration that the snack bar is open, then fails with "Failed to find element".
Environment
Commentary
Using the same test code, I can test a snack bar that was opened without a duration. But if my production code does use a duration it does not appear possible to test it with the harness. Am I missing something? I assume assigning a duration is a common use-case.
The text was updated successfully, but these errors were encountered: