有人帮助我吗?我需要为这个订阅写一个单元测试。
public ngOnInit(): void {
this.notificationService.notifier.do((message) => {
this.messageNotification = message;
})
.switchMap((message) => Observable.timer(2500))
.subscribe((timer) => this.messageNotification = undefined);
}
我设法超越了'do',但我无法通过订阅。
这是我的测试:
it('subscribe, do, switchMap', () => {
const t = 2500;
expect(() => {
component.ngOnInit();
notifyService.notify('error', 'mensagem');
notifyService.notifier.do((message) => {
expect(component.messageNotification)
.toBeDefined();
})
.switchMap((message) => Observable.timer(t))
.subscribe((timer) => {
component.messageNotification = undefined;
expect(timer)
.toBe(2500);
});
}).not
.toThrow();
});