尝试在 React 中异步操作创建者时如何摆脱使用绝对 url 错误?

How to get rid of use absolute urls error when trying to async action creators in React?

当我尝试使用 fetchMocknock 模拟测试调用时,我不断收到错误提示,我需要使用来自 fetch 的绝对 URL .

describe('fetchFileNames creator @AT-fetchTodosIfNeeded@', () => {
    it('should create RECEIVE_FILE_NAMES_SUCCESS after the fetching is done', () => {

        const fileNames = ['testFile1', 'testFile2', 'testFile3'];
        const expectedActions = [
            { type: ac.REQUEST_FILE_NAMES },
            { type: ac.RECEIVE_FILE_NAMES_SUCCESS, fileNames }
        ];
        const store = mockStore({
            files: {
                fileNames
            }
        });

        fetchMock.get('*', { files: fileNames});

        return store.dispatch(at.fetchFileNames())
            .then(() => {
                var createdActions = store.getActions();
                delete createdActions[1].receivedAt;
                expect(store.getActions()).to.deep.equal(expectedActions);
            });
    });
});

代码结果没问题。我错误地将 isomorphic-fetch 导入到异步操作创建者文件中。我在做什么:import fetch from isomorphic-fetch 我应该做什么:import isomorphic-fetch。它记录在 fetch-mock 中,但我错过了它,这让人很沮丧。