[英]How to get rid of use absolute urls error when trying to async action creators in React?
I keep getting the error that I need to use absolute URL's from fetch
when I am trying to mock the test call with fetchMock
and nock
. 当我尝试使用fetchMock
和nock
模拟测试调用时,我不断收到需要从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);
});
});
});
The code turned out to be okay. 该代码证明还可以。 I was importing isomorphic-fetch
incorrectly into the async action creators file. 我将isomorphic-fetch
错误地导入了异步动作创建者文件。 What I was doing: import fetch from isomorphic-fetch
what I should have been doing: import isomorphic-fetch
. 我正在做什么: import fetch from isomorphic-fetch
我应该做的事情: import isomorphic-fetch
。 It's documented in fetch-mock
, but I missed it and this was getting frustrating. 它记录在fetch-mock
,但是我错过了它,这越来越令人沮丧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.