我目前正试图覆盖 100% 的功能,但我面临一个未覆盖的分支,它不明白为什么它没有被覆盖,甚至不明白如何修复和覆盖它。
它尝试了许多不同的测试,但没有改变任何东西。如果问题来 self 或 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({});
});
我希望通过实际测试涵盖所有功能。
我的 jest 版本是 23.4.1
,以防万一。
最佳答案
您只需在 ts-jest 的 tsConfig
文件中指定目标 esnext
。
// jest.config.js
module.exports = {
...
'ts-jest': {
....
tsConfig: './tsconfig.json'),
},
// tsconfig.json
{
...,
"target": "esnext",
}
关于javascript - 为什么在 Jest 中分支没有被 rest 参数覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55863723/