【发布时间】:2020-06-16 16:28:28
【问题描述】:
我想用 jasmine marble 测试 ngLogger 函数,但是出错了
Expected $.length = 2 to equal 1.
Expected $.length = 2 to equal 1.
Expected $[0].frame = 0 to equal 10.
Expected $[0].notification.value to be a kind of Observable, but was Object({ type: 'TECHNICAL', level: 'ERROR', msg: 'test' }).
Expected $[1] = Object({ frame: 0, notification: Notification({ kind: 'C', value: undefined, error: undefined, hasValue: false }) }) to equal undefined.
测试:
export namespace GlobalUtils {
export function ngLogger(error: string):
Observable<Log> {
return of({ type: LogEnum.TECHNICAL,
level: LevelEnum.ERROR,
msg: error } as Log
);
}
}
import { GlobalUtils } from './global.utils';
it('ngLogger should be return an Observable', () => {
const expected = of({
type: LogEnum.TECHNICAL,
level: LevelEnum.ERROR,
msg: 'test'
});
const expected$ = hot('-a', { a: expected });
const result$ = GlobalUtils.ngLogger('test');
expect(result$).toBeObservable(expected$);
});
const expected$ = hot('a', { a: expected }); 没有任何区别。 const expected$ = hot('a|', { a: expected }); 报错:
Expected $[0].notification.value to be a kind of Observable, but was Object({ type: 'TECHNICAL', level: 'ERROR', msg: 'test' }).
Expected $[1].frame = 0 to equal 10
然后我改变了
const expected = of({
type: LogEnum.TECHNICAL,
level: LevelEnum.ERROR,
msg: 'test'
});` to `const expected = of({
type: LogEnum.TECHNICAL,
level: LevelEnum.ERROR,
msg: 'test'
});
我收到错误Expected $[1].frame = 0 to equal 10.
什么意思?
【问题讨论】:
-
const expected$ = hot('a', { a: expected });甚至const expected$ = hot('a|', { a: expected });? -
const expected$ = hot('a', { a: expected });没有任何区别。 -
现在我看到你有两个问题首先是大理石应该是
(a|)因为这是你描述同时发射和结束可观察的方式,这是在使用of时完成的第二个问题是你有你的预期定义为可观察的,它应该只是里面的数据
标签: angular rxjs jasmine-marbles