gpt4 book ai didi

typescript - "No reducer provided for key X"console.error in redux jest 测试

转载 作者:行者123 更新时间:2023-12-04 02:00:45 33 4
gpt4 key购买 nike

我有一个 reducer 测试通过了,但最后抛出了这个奇怪的错误:

console.error node_modules/redux/lib/utils/warning.js:14
No reducer provided for key "newProducts"

src/reducer/index.ts

import newLineItemReducer from "./newLineItemReducer";
import renewedLineItemReducer from "./renewedLineItemReducer";

export interface LineItemState{
renewedProducts: LineItem[]
newProducts: LineItem[]
}

//used by both reducers
export interface LineItem{
...
}

// used by both "new" and "renewed" slice reducers
export function sharedFunction1() {
...
}

export default combineReducers<LineItemState>({
renewedProducts: renewedLineItemReducer,
newProducts: newLineItemReducer
});

src/reducer/newLineItemReducer.ts

import {LineItem, sharedFunction1 } from "./";

type Action = ...;
const newLineItemReducer =
(state: LineItem[] = [], action: Action): LineItem[] => {
switch (action.type) {
case ...:
sharedFunction1(state, action.foo);
}
}
export default newLineItemReducer;

测试/newLineItemReducer.spec.ts

import newLineItemReducer from "@src/reducers/newLineItemReducer";
test("foo", () => {
let state = //
let action = //
const updatedState = newLineItemReducer(state, action);
...
});

奇怪的是没有代码实际从 index 调用根 reducer。我的测试是直接调用切片“newLineItemReducer”。似乎只是从 reducer/index.ts 导入共享接口(interface)和 case 函数的行为导致了问题(如果我删除 combineReducer 导出没有错误)?

最佳答案

我遇到了同样的问题,正如@michael-radionov 在上面的评论部分中提到的,这是一个循环导入,我使用了 circular-dependency-plugin跟踪这些循环导入的插件,有关插件使用的更多信息可以在插件仓库或以下 article 中找到

关于typescript - "No reducer provided for key X"console.error in redux jest 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47441905/

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