1

I am trying to test a Redux action creator and am not able to get the .then of the returned promise to execute. I am using Moxios to mock my HTTP requests which are coming from Axios. Here is the Moxios setup:

import moxios from "moxios"

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



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

      afterEach(() => {
        moxios.uninstall(backend);   });

And here is the spec that tests this action creator:

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: []
      }]);
    });
  });

I checked that the action returns a promise, and no error is created. Anyone see anything I did incorrectly here?

Arun
  • 626
  • 10
  • 29

0 Answers0