仅测试是否调用了 ngrx 操作就足够了吗? (单元测试)

Is it enough to only test if ngrx action was called? (unit test)

假设我在一个组件中有以下代码,它是 public 并在视图中使用:

removeItemFromCart(item: CartItem): void {
  this.store$.dispatch(OrderingStoreActions.removeItemFromCart({ cartItem: item }));
}

在单元测试中,只测试动作是否已发送就够了吗?

it("should remove the item from the cart", () => {
    const item = <CartItem>{ amount: 1, product: { id: "p" } };
    component.removeItemFromCart(item);
    expect(store.dispatch).toHaveBeenCalledWith(OrderingStoreActions.removeItemFromCart({ cartItem: item  }));
});

或者如果操作结果是在特征存储上执行的,我应该在模拟存储中测试吗?

您应该对您的代码正确使用给定的 API/library 进行单元测试,而不是 API/library 是否有效(这将是一个集成测试)。因此,您需要确认该操作已使用您打算发送给它的参数进行分派。你在这里展示的测试就足够了。