Javascript 为什么分支没有被rest参数所覆盖?
我目前正试图覆盖我的100%功能,但我面临一个未覆盖的分支,它不明白为什么未覆盖,甚至不知道如何修复和覆盖它 它尝试了许多不同的测试,但没有改变任何事情。我不知道问题是来自我还是玩笑 我的功能Javascript 为什么分支没有被rest参数所覆盖?,javascript,typescript,ecmascript-6,jestjs,Javascript,Typescript,Ecmascript 6,Jestjs,我目前正试图覆盖我的100%功能,但我面临一个未覆盖的分支,它不明白为什么未覆盖,甚至不知道如何修复和覆盖它 它尝试了许多不同的测试,但没有改变任何事情。我不知道问题是来自我还是玩笑 我的功能 export const removeProductInList=(状态:IItems,操作:IBasketRemoveProductAction)=>{ 常数{ 有效负载:{uuid}, }=行动; const{[uuid]:itemToRemove,…restOfItems}=state; 返回re
export const removeProductInList=(状态:IItems,操作:IBasketRemoveProductAction)=>{
常数{
有效负载:{uuid},
}=行动;
const{[uuid]:itemToRemove,…restOfItems}=state;
返回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
,以防万一。尝试用额外的属性测试removeProductList
expect(removeProductInList({ [mockUuid1]: mockItem1, extraProp: 'someValue' }, removeProduct(mockUuid1))).toEqual({});
您只需在ts jest中的
tsConfig
文件中指定目标esnext
//jest.config.js
module.exports={
...
“开玩笑”{
....
tsConfig:'/tsConfig.json'),
},
您可能会使用
state
测试它,只使用uuid
propI我认为这就是我在测试中所做的不?expect(removeProductInList(mockListItems,removeProduct(mockUuid1))。toEqual({[mockUuid2]:mockItem2});
谢谢!我确实怀疑有配置问题
// tsconfig.json
{
...,
"target": "esnext",
}