我正在尝试测试一个Redux动作创建者,并且无法获得返回的promise的.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: []
}]);
});
});
我检查了该操作是否返回了一个promise,并且没有创建错误。有人看到我在这里做错了吗?