gpt4 book ai didi

javascript - TypeError : routingState. 等于不是函数 | Jest 测试用例

转载 作者:行者123 更新时间:2023-12-03 00:45:19 25 4
gpt4 key购买 nike

这是我的selector.js 文件:-

const makeSelectLocationState = () => {
let prevRoutingState;
let prevRoutingStateJS;

return (state) => {
const routingState = state.get('route'); // or state.route

if (!routingState.equals(prevRoutingState)) {
prevRoutingState = routingState;
prevRoutingStateJS = routingState.toJS();
}

return prevRoutingStateJS;
};
};

以及我编写的以下测试用例:-

it('makeSelectLocationState function testing', () => {
const selectLocationState = makeSelectLocationState();
const mockedState = fromJS({
route: '',
});
expect(selectLocationState(mockedState)).toEqual('');
});

使用 jest 运行测试用例时出现以下错误:-

TypeError: routingState.equals is not a function

最佳答案

问题出在这里:

const routingState = state.get('route'); 

感觉您没有获得routingState,可能未定义,因此您将收到上述错误消息。因此请检查routingState的日期。

并在测试文件中,将mockedState传递给selectLocationState

selectLocationState(mockedState)

但是,makeSelectLocationState函数没有属性。也许更改为:

const makeSelectLocationState = (state) => {}

关于javascript - TypeError : routingState. 等于不是函数 | Jest 测试用例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53274746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com