Skip to content

Commit

Permalink
Test for overriding global delay if delay per request is provided
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 fd65afa commit d7997d6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,37 @@ describe("MockAdapter basics", function () {
})
]);
});

it("overrides global delay if request per delay is provided and respects global delay if otherwise", function () {
const start = new Date().getTime();
const requestDelay = 100;
const globalDelay = 500;
const success = 200;
mock = new MockAdapter(instance, { delayResponse: globalDelay });

const fooOnDelayResponds = mock.onGet("/foo").withDelayInMs(requestDelay);
fooOnDelayResponds(success);
mock.onGet("/bar").reply(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(requestDelay);
//Ensure global delay is not applied
expect(totalTime).lessThan(globalDelay);
}),
instance.get("/bar").then(function (response) {
const end = new Date().getTime();
const totalTime = end - start;

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

it("maps empty GET path to any path", function () {
mock.onGet("/foo").reply(200, "foo").onGet().reply(200, "bar");
Expand Down

0 comments on commit d7997d6

Please sign in to comment.