效果器:".use argument should be a function"连接时



效应器抛出错误"。use参数应该是一个函数";在测试时附加方法上的getCurrent(node_modules/effecter/effector/reregion.ts:27:5(。

我正在尝试对一些初始状态进行模拟集成测试。

//babel config
module.exports = (api) => {
if (api.env('test')) {
config.plugins.push([
'module-resolver',
{
root: ['.'],
alias: {
effector-react: 'effector-react/scope',
},
},
]);
}
return config;
};
//store.ts
export const getUsersFx = attach({
effect: getUsersOriginalFx,
source: [$clientId],
mapParams: (_, [clientId]) => ({
clientId
}),
});
//component.tsx
import { render } from '@testing-library/react';
import { Provider } from 'effector-react/scope'
describe('TestableComponent', () => {
test('should increment counter after click', () => {
const scope = fork()
const rendered = render(
<Provider value={scope}>
<TestableComponent />
</Provider>
);
})
})

我认为原因是Effector模拟Effect,而在后台使用.use进行效果回调模拟。但随后它将其更改为null或未定义,Effector抛出错误。use(fn(中的fn必须是函数

效应器模拟getUsersFx=>getUsersFx.use(mockFn<-我认为这是未定义的(。

效应器版本:22

看起来原因是您用于测试的effector/babel插件多次通过-附加错误类似:https://github.com/effector/effector/issues/601

babel插件的多次通过将在effector的下一个小版本中得到支持-现在你可以检查你的babel配置是否重复使用effector/babel插件

相关内容

最新更新