我不确定在以下测试中热/冷响应如何工作。我已将测试配置为期望比萨服务提供响应,并使用下面的可观察的大理石测试来测试该响应。但是看起来在实际响应中我会遇到额外的事件吗?我不知道如何-额外的事件正在破坏测试!
这是我要测试的效果。它调用披萨服务,并成功返回所有披萨。目的是编写一个可观察的测试,以检查从Pizza Pizza服务返回的最终可观察结果是否与测试中的期望相符
getPizzas$ = this.actions$.pipe(
ofType<GetAllPizzas>(PizzaTypes.GetPizzas,
withLatestFrom(
this.store$.pipe(select(fromRootStore.getPizzaId))
),
take(1),
exhaustMap(([customAction, pizzaId]): any => {
if (!pizzaId) {
map(() => new BigProductError({ .
appmessage : "Boom"
}));
} .
return this.pizzaService.getPizzas(customAction.orderDetails, pizzaId)
.pipe(
map((pizzas) => new LoadPizzasSuccess(pizzas)),
catchError(error => of(new LoadPizzasFailure(error)))
);
})
);
我写的测试是:
describe('GetPizzas', () => {
test(`
Get Pizzas successfully
`, () => {
const action = new GetAllPizzas();
const success = new GetAllPizzasSuccess({'NumberOfPizzas': 2});
actions$ = hot('-a', { a: action });
const resp = cold('-a|', { a: { NumberOfPizzas: 2 } });
const exp = cold('--a', { a: success });
pizzaService.getPizzas = jest.fn(() => resp);
expect(effects.pizzaService$).toBeObservable(exp);
});
感觉我在响应中遇到了一个额外的可观察事件(下面的响应末尾有额外的IFRAME 30)。但我无法将其纳入测试。
Expected value to equal:
[{"frame": 20, "notification": {"error": undefined, "hasValue": true, "kind": "N",
"value": {"payload": {"NumberOfPizzas": 2}, "type": "[Pizzas API] Get All Pizzas Success"}}}]
Received:
[{"frame": 20, "notification": {"error": undefined, "hasValue": true, "kind": "N",
"value": {"payload": {"NumberOfPizzas": 2}, "type": "[[Pizzas API] Get All Pizzas Success"}}},
{"frame": 30, "notification": {"error": undefined, "hasValue": false, "kind": "C", "value": undefined}}]