gpt4 book ai didi

testing - 使用 Webpack+karma+etc 进行 Redux 异步测试

转载 作者:行者123 更新时间:2023-11-28 20:29:08 26 4
gpt4 key购买 nike

我试图做一个异步 Action 测试,但失败得很惨:(

有问题的测试是这个:https://github.com/persocon/destiny-weekly/blob/test/test/actions/index.spec.jsx

enter image description here

我收到此错误消息:

1) fill in GET_OPTIONS when fetching all options is done Async Actions undefined is not an object (evaluating 'store.dispatch(actions.getOptions()).then') /Users/persocon/Projects/destiny-weekly/test/test.bundle.js:14669:42 <- webpack:///test/actions/index.spec.jsx:49:7

我不知道那是什么意思,如果这是为了帮助我,我会比以往任何时候都更加困惑。

更新

必须在操作本身而不是我使用的 $.get 上实现获取,但现在我收到一个指向我的操作的新错误:v 即使它在浏览器上工作:

1) fill in GET_OPTIONS when fetching all options is done Async Actions Can't find variable: fetch /Users/persocon/Projects/destiny-weekly/test/test.bundle.js:42473:9 <- webpack:///src/app/javascript/actions/index.jsx:32:9 /Users/persocon/Projects/destiny-weekly/test/test.bundle.js:15691:23 <- webpack:///~/redux-thunk/lib/index.js:12:0 /Users/persocon/Projects/destiny-weekly/test/test.bundle.js:14669:20 <- webpack:///test/actions/index.spec.jsx:48:19

更新 2 Action 代码:

const setOptions = (result) => {
return {
type: 'GET_OPTIONS',
options: result
}
}

const getOptions = () => {


return dispatch => {
dispatch(startLoading())
return fetch('/api/selectActivity')
.then(response => response.json())
.then( json => {
dispatch(doneLoading());
json.unshift({advisorTypeCategory: "Selecione Uma Atividade", identifier: "", disabled: "disabled"});
dispatch(setOptions(json));
}
)
}
}

最佳答案

是的,Async Action Creators Example 使用的是“fetch”,这有点做作,但理论上应该可行。一个简单的解决方案可能是用这个 isomorphic fetch library 来实现它.祝你好运!

关于testing - 使用 Webpack+karma+etc 进行 Redux 异步测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123641/

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