Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 测试Redux异步操作创建者不调用.then()_Reactjs_Redux_Jestjs_Axios_Moxios - Fatal编程技术网

Reactjs 测试Redux异步操作创建者不调用.then()

Reactjs 测试Redux异步操作创建者不调用.then(),reactjs,redux,jestjs,axios,moxios,Reactjs,Redux,Jestjs,Axios,Moxios,我正在尝试测试Redux操作创建者,但无法获得返回的执行承诺的.then。我使用Moxios模拟来自Axios的HTTP请求。以下是Moxios设置: import moxios from "moxios" import backend from "../../utils/backend"; beforeEach(() => { moxios.install(backend); }); afterEach(() => { mo

我正在尝试测试Redux操作创建者,但无法获得返回的执行承诺的.then。我使用Moxios模拟来自Axios的HTTP请求。以下是Moxios设置:

import moxios from "moxios"

import backend from "../../utils/backend";



beforeEach(() => {
        moxios.install(backend);   });

      afterEach(() => {
        moxios.uninstall(backend);   });
以下是测试此动作创建者的规范:

it("Creates GET_TRENDING_TOPICS_SUCCESS when fetching trending topics is successful", () => {
    moxios.stubRequest("/trending-topics/", {
      status: 200,
      response: {
        data: {
          results: []
        }
      }
    });

    const store = mockStore(initialState);

    store
    .dispatch(actions.getTrendingTopics())
    .then(() => {
      // Nothing in here is executed...

      expect(store.getActions())
      .toEqual([{
        type: "GET_TRENDING_TOPICS_SUCCESS",
        payload: []
      }]);
    });
  });

我检查了操作是否返回承诺,并且没有创建错误。有人看到我在这里做错了什么吗?

谁负责API调用?如果您使用的是中间件,是否已将其注册到模拟存储区?请尝试使用nock进行测试;)我遇到了类似的问题,通过切换到
async
/
wait
而不是
then
,绕过了它。谁负责进行API调用?如果您使用的是中间件,是否已将其注册到模拟存储区?请尝试使用nock进行测试;)我遇到了类似的问题,并通过切换到
async
/
wait
而不是
then
绕过了它。