我需要导入json数据以运行React Redux测试。如何将devMock.json导入dashboard.test.js?我可以不安装依赖项就做吗?
devMock.json
{
"data": {
"0": 11,
"1": 1
},
"polarity_freq": {
"negative": 214,
"positive": 220
},
"sentiments_freq": {
"anger": 1,
"fear": 0,
"sad": 2,
"joy": 11
}
},
dashboard.test.js
import * as actions from '../actions/dashboardActions';
import * as types from '../actions/actionTypes';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import expect from 'expect';
import fetchMock from 'fetch-mock';
const middlewares = [ thunk ]
const mockStore = configureMockStore(middlewares)
describe('Dashboard action creators should be called', () => {
afterEach(() => {
fetchMock.reset()
})
您可以将.json文件更改为.js。像那样:
export {
"data": {
"0": 11,
"1": 1
},
"polarity_freq": {
"negative": 214,
"positive": 220
},
"sentiments_freq": {
"anger": 1,
"fear": 0,
"sad": 2,
"joy": 11
}
};
之后,只需将其导入为普通的.JS文件即可。
import DevMock from './devMock.js';
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句