【发布时间】:2019-09-15 17:43:15
【问题描述】:
我目前正在尝试覆盖 100% 的功能,但我面临一个未覆盖的分支,它不明白为什么它没有被覆盖,甚至不明白如何修复和覆盖它。
它尝试了许多不同的测试,但并没有改变任何东西。如果问题来自我或 Jest,我不知道?
我的功能
export const removeProductInList = (state: IItems, action: IBasketRemoveProductAction) => {
const {
payload: { uuid },
} = action;
const { [uuid]: itemToRemove, ...restOfItems } = state;
return restOfItems;
};
我的测试
product1 = { id: 1 };
product2 = { id: 2 };
mockUuid1 = 'IdTest';
mockUuid2 = 'IdTest2';
mockItem1 = { product: product1, quantity: 1 };
mockItem2 = { product: product2, quantity: 1 };
mockListItems = {
[mockUuid1]: mockItem1,
[mockUuid2]: mockItem2,
};
it('should handle PRODUCT__REMOVE', () => {
expect(removeProductInList({ [mockUuid1]: mockItem1 }, removeProduct(mockUuid1))).toEqual({});
expect(removeProductInList(mockListItems, removeProduct(mockUuid1))).toEqual({ [mockUuid2]: mockItem2 });
expect(removeProductInList({}, removeProduct('acac'))).toEqual({});
});
我希望通过我的实际测试涵盖所有功能。
我的笑话版本是23.4.1,以防万一。
【问题讨论】:
-
您可能会使用
state仅使用uuid属性对其进行测试
标签: javascript typescript ecmascript-6 jestjs