0
我是新来Redux的测试,并已尝试备份填补测试的应用程序,我做出很抱歉,如果这是完全错误的方式去与箭扣和测试终极版 - 模拟商店。与箭扣和终极版,模拟店误差终极版动作测试
//Action in authAction.js
export function fetchMessage() {
return function(dispatch) {
axios.get(ROOT_URL, {
headers: { authorization: localStorage.getItem('token') }
})
.then(response => {
console.log("hi")
dispatch({
type: FETCH_MESSAGE,
payload: response.data.message
});
})
.catch(response => {
console.log(response)
//callingRefresh(response,"/feature",dispatch);
});
}
}
这是方法,它似乎越来越调用,但通常去的头不匹配诺克失败原因渔获原因。
//authActions_test.js
import nock from 'nock'
import React from 'react'
import {expect} from 'chai'
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
const middlewares = [ thunk ]
const mockStore = configureMockStore(middlewares)
import * as actions from '../../src/actions/authActions';
const ROOT_URL = 'http://localhost:3090';
describe('actions',() => {
beforeEach(() => {
nock.disableNetConnect();
localStorage.setItem("token", '12345');
});
afterEach(() => {
nock.cleanAll();
nock.enableNetConnect();
});
describe('feature',() => {
it('has the correct type',() => {
var scope = nock(ROOT_URL).get('/',{reqheaders: {'authorization': '12345'}}).reply(200,{ message: 'Super secret code is ABC123' });
const store = mockStore({ message: '' });
store.dispatch(actions.fetchMessage()).then(() => {
const actions = store.getStore()
expect(actions.message).toEqual('Super secret code is ABC123');
})
});
});
});
即使当标题被移除并且nock截取了该呼叫。我每次
TypeError: Cannot read property 'then' of undefined
at Context.<anonymous> (test/actions/authActions_test.js:43:24)
这个测试主要是为了正确地确保所有的行动过程中的反应,并与修正行为产生回应。我打算在另一个文件测试减速,以确保一旦他们接受正确的负载和输入状态看起来是正确的后 – Mike