Skip to content

Commit 8aaab1a

Browse files
committed
Add test for delayResponse
1 parent f1abc8e commit 8aaab1a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ function adapter() {
2222
config: config
2323
}, this.delayResponse);
2424
} else {
25-
utils.settle(resolve, reject, { status: 404, config: config }, this.delayResponse);
25+
utils.settle(resolve, reject, {
26+
status: 404,
27+
config: config
28+
}, this.delayResponse);
2629
}
2730
}.bind(this);
2831
}
@@ -41,7 +44,9 @@ function MockAdapter(axiosInstance, options) {
4144
if (axiosInstance) {
4245
this.axiosInstance = axiosInstance;
4346
this.originalAdapter = axiosInstance.defaults.adapter;
44-
this.delayResponse = options && options.delayResponse > 0 ? options.delayResponse : null;
47+
this.delayResponse = options && options.delayResponse > 0
48+
? options.delayResponse
49+
: null;
4550
axiosInstance.defaults.adapter = adapter.call(this);
4651
}
4752
}

test/basics.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,16 @@ describe('MockAdapter basics', function() {
229229
expect(mock.handlers['patch'].length).to.equal(1);
230230
expect(mock.handlers['post'].length).to.equal(2);
231231
});
232+
233+
it('allows to delay responses', function(done) {
234+
mock = new MockAdapter(instance, { delayResponse: 1 });
235+
236+
mock.onGet('/foo').reply(200);
237+
238+
instance.get('/foo')
239+
.then(function(response) {
240+
expect(response.status).to.equal(200);
241+
done();
242+
});
243+
});
232244
});

0 commit comments

Comments
 (0)