Redux-loop,Jest,Ease和Moxios的集成测试

时间:2019-07-22 09:02:50

标签: jestjs integration-testing enzyme moxios redux-loop

我需要在redux-loop中进行集成测试

我使用了他们的站点上提供的用于测试reducer的教程来测试我的初始代码,但是现在我想进行一些集成测试。

import { appStore } from '../store';
import moxios from 'moxios';
...
describe('Init', () => {
  beforeEach(() => {
    moxios.install();
  });

  afterEach(() => {
    moxios.uninstall();
  });
  test('Store is updated correctly', () => {
    const expectedState = {
    }

    moxios.wait(() => {
        const request = moxios.requests.mostRecent();
        request.respondWith({
            status: 200,
            response: {
                data: 
                    { 
                        z: [[1, 2], [3, 4]] 
                    }
            }
        })
    });
    return appStore.dispatch(init('1234567'))
    .then((res: any) => {
        const newState = appStore.getState();
        expect(newState).toBe(expectedState);
    });
  });
});

我的减速器看起来像这样:

return loop ( {...state}, Cmd.list(callAFunc(action.payload.param, callAnAction)) );

我希望测试失败,但是我得到以下信息: 超时-jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时时间内未调用异步回调。

在测试中执行console.log(appStore.dispatch(init('1234567')))会返回未完成的承诺,但不会执行.then。我知道我做错了事,我使用了此https://redux-loop.js.org/docs/tutorial/Testing.html教程来测试我的reducer,但需要进行集成测试。

0 个答案:

没有答案