Skip to content

Commit

Permalink
Test for delay in multiple requests
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanth-92 authored and marcbachmann committed Sep 11, 2023
1 parent 1ae9f60 commit 2a405c1
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,18 +556,34 @@ describe("MockAdapter basics", function () {
});
});

it("allows delay in milliseconds", function () {
it("allows delay in millsecond per request", function () {
mock = new MockAdapter(instance);
const start = new Date().getTime();
const delayInMs = 10;
mock.delayInMs(delayInMs).onGet("/foo").reply(200);
const firstDelay = 100;
const secondDelay = 500;
const success = 200;

return instance.get("/foo").then(function (response) {
const end = new Date().getTime();
const totalTime = end - start;
expect(response.status).to.equal(200);
expect(totalTime).greaterThan(delayInMs);
});
const fooOnDelayResponds = mock.onGet("/foo").withDelayInMs(firstDelay);
fooOnDelayResponds(success);
const barOnDelayResponds = mock.onGet("/bar").withDelayInMs(secondDelay);
barOnDelayResponds(success);

return Promise.all([
instance.get("/foo").then(function (response) {
const end = new Date().getTime();
const totalTime = end - start;

expect(response.status).to.equal(success);
expect(totalTime).greaterThanOrEqual(firstDelay);
}),
instance.get("/bar").then(function (response) {
const end = new Date().getTime();
const totalTime = end - start;

expect(response.status).to.equal(success);
expect(totalTime).greaterThanOrEqual(secondDelay);
})
]);
});

it("maps empty GET path to any path", function () {
Expand Down

0 comments on commit 2a405c1

Please sign in to comment.