For angular material snackbar I just use the official example and write unit test for the component.
In the test,I use loader with documentRootLoader and MarSnackbarHarness to check whether the snack bar display,it passed. But if I add the duration parameter to the open function,it will can’t find the snackbar element.
Anyone could explain why it can’t get the element and how can I check the display of snack bar element?
It seems snackbar requires animations to work, might be due to the delay animation (not sure). The solution is to add provideAnimations
to the providers
array of the TestBed.
...
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
SnackBarOverviewExample,
MatSnackBarModule,
],
providers: [
provideAnimations(),
]
}).compileComponents();
...