help(MatSnackBarHarness): How do you use the snackbar harness when there is no fixture?
What are you trying to do?
Write tests for an NgRx effects class which loads the snackbar on certain actions. (Or equivalently a service which does the same)
Reproduction
e.g.
@Injectable()
export class MyEffects {
doingTheThing$ = createEffect(() =>
this.actions$.pipe(
ofType(MyActions.doTheThing),
tap(() => {
const snackBarRef = this.snackBar.open(
`Some snackbar message`,
'Action?',
{ duration: 5000 }
);
snackBarRef.onAction().subscribe(() => {
this.store.dispatch(MyActions.someOtherAction());
});
})
)
);
constructor(
private actions$: Actions,
private snackBar: MatSnackBar,
private store: Store<MyDataSlice>
) {}
}
or
@Injectable()
export class MyService {
constructor(
private snackBar: MatSnackBar
) {}
doTheThing() {
const snackBarRef = this.snackBar.open(
`Some snackbar message`,
'Action?',
{ duration: 5000 }
);
snackBarRef.onAction().subscribe(() => {
doSomeOtherThing();
});
}
doSomeOtherThing() {
// todo
}
}
How do I test either of these cases? Do I have to create a test host that does nothing?
Environment
- Angular: 11.2.3
- CDK/Material: 11.2.2
I'm not sure that's possible at the moment since you don't have a way of triggering change detection without the fixture. @mmalerba should know more about it.
Yeah, the harness needs a fixture to be able to trigger change detection. Creating a dummy component like you suggested is probably the best way to handle this.
😞 @crisbeto @mmalerba Thanks for the quick response and the confirmation. I guess I'll do that then.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.