我写了一个过滤输入可观察的管道。在管道中,如果源未及时发出预期值,我使用 timeout() 运算符指定超时以中止等待。我想用 jasmine-marbles 测试超时情况,但我无法让它工作。我相信那expect(source).toBeObservable()源发出之前先计算。
待测管道:
source = cold('a', { a: { id: 'a' } }).pipe(
timeout(500),
filter((a) => false),
catchError((err) => {
return of({ timeout: true })
}),
take(1)
);
Run Code Online (Sandbox Code Playgroud)
使用 toPromise() 进行测试按预期工作:
expect(await source.toPromise()).toEqual({ timeout: true });
Run Code Online (Sandbox Code Playgroud)
用茉莉花大理石测试
const expected = cold('500ms (a|)', { a: { timeout: true } });
expect(source).toBeObservable(expected);
Run Code Online (Sandbox Code Playgroud)
因错误而失败
Expected $.length = 0 to equal 2.
Expected $[0] = undefined to equal Object({ frame: 500, notification: Notification({ kind: 'N', …Run Code Online (Sandbox Code Playgroud)