我正在尝试使用karma服务器和nock创建一些基本测试.似乎nock根本没有拦截我的请求,有没有人有想法?我无法弄清楚遗漏了什么.我仍然得到真实的数据.
nock('https://api.github.com/users/' + username).log(console.log)
.get('/')
.query(true)
.reply(400, {
statusMessage: 'Bad Request',
foo: 'foo'
})
http.get('https://api.github.com/users/' + username, function(res) {
console.log('res', res)
})
Run Code Online (Sandbox Code Playgroud)
我还添加了这个中间件
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
Run Code Online (Sandbox Code Playgroud)
======更新6月6日======
使用react-redux的整个流程这是我的测试:
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import axios from 'axios';
import expect from 'expect';
import * as actions from 'actions/test-actions'
import * as types from 'types';
import nock from 'nock'
import { username } from 'constansts'
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
describe('Asynchronous …Run Code Online (Sandbox Code Playgroud)