Replaced mockjax with axios-mock-request
This commit is contained in:
parent
4fe9676318
commit
a58c36c9b4
|
@ -16,6 +16,7 @@
|
|||
"test": "export NODE_PATH=src && mocha src/lib-test/preprocessor.js --compilers js:babel-core/register --recursive src/**/**/__tests__/*-test.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios-mock-adapter": "^1.15.0",
|
||||
"babel-core": "^5.8.22",
|
||||
"babel-plugin-transform-class-properties": "^6.11.5",
|
||||
"babel-register": "^6.7.2",
|
||||
|
@ -42,7 +43,6 @@
|
|||
"gulp-uglify": "^2.1.2",
|
||||
"gulp-util": "^3.0.6",
|
||||
"humps": "^0.6.0",
|
||||
"jquery-mockjax": "^2.1.0",
|
||||
"jsdom": "^8.4.1",
|
||||
"morgan": "^1.6.1",
|
||||
"proxyquire": "^1.7.4",
|
||||
|
@ -61,7 +61,6 @@
|
|||
"draft-js": "^0.10.0",
|
||||
"draft-js-export-html": "^0.5.2",
|
||||
"history": "^3.0.0",
|
||||
"jquery": "^2.1.4",
|
||||
"keycode": "^2.1.4",
|
||||
"localStorage": "^1.0.3",
|
||||
"lodash": "^3.10.0",
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
const _ = require('lodash');
|
||||
const $ = require('jquery');
|
||||
const mockjax = require('jquery-mockjax')($, window);
|
||||
const axios = require('axios');
|
||||
const MockAdapter = require('axios-mock-adapter');
|
||||
const qs = require('qs');
|
||||
const mock = new MockAdapter(axios);
|
||||
|
||||
let fixtures = (function () {
|
||||
let fixturesData = [];
|
||||
|
@ -23,12 +25,9 @@ fixtures.add(require('data/fixtures/system-fixtures'));
|
|||
fixtures.add(require('data/fixtures/article-fixtures'));
|
||||
|
||||
_.each(fixtures.getAll(), function (fixture) {
|
||||
mockjax({
|
||||
contentType: fixture.contentType || 'application/json',
|
||||
url: 'http://localhost:3000/api' + fixture.path,
|
||||
responseTime: fixture.time || 500,
|
||||
response: function (settings) {
|
||||
this.responseText = fixture.response(settings.data);
|
||||
}
|
||||
mock.onAny('http://localhost:3000/api' + fixture.path).reply(function(config) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
setTimeout(() => resolve([200, fixture.response(qs.parse(config.data))]), fixture.time || 500);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ const APIUtils = {
|
|||
};
|
||||
|
||||
if(!dataAsForm){
|
||||
options.headers = {'content-type': 'application/x-www-form-urlencoded'},
|
||||
options.headers = {'content-type': 'application/x-www-form-urlencoded'};
|
||||
options.data = qs.stringify(options.data);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue