diff --git a/public/guide.html b/public/guide.html index ca2ee02..a887791 100644 --- a/public/guide.html +++ b/public/guide.html @@ -181,6 +181,12 @@

Nested resources

  • https://jsonplaceholder.typicode.com/users/1/todos
  • https://jsonplaceholder.typicode.com/users/1/posts
  • +

    Delay

    +

    With any request, add a delay=N query string parameter to simulate a slow-running API response.

    +

    diff --git a/public/index.html b/public/index.html index 3e2d875..265a419 100644 --- a/public/index.html +++ b/public/index.html @@ -251,6 +251,14 @@

    Routes

    here.

    + +

    Simulate a delay

    + +

    + You can simulate a delay by adding a + delay query parameter (measured in milliseconds) to any route. +

    +

    Use your own data

    +

    Simulate a delay

    + +

    + You can simulate a delay by adding a + delay query parameter (measured in milliseconds) to any route.

    diff --git a/test/app.js b/test/app.js index 8c2036b..4af92cd 100644 --- a/test/app.js +++ b/test/app.js @@ -8,6 +8,18 @@ test('GET /', (t) => { .expect(200, (err) => t.end(err)) }) +test('GET /?delay=100', (t) => { + const start = Date.now() + request(app) + .get('/?delay=100') + .expect(200, (err) => { + const end = Date.now() + t.assert(end - start >= 100, `actual response time ${end - start}`) + t.assert(end - start < 200, `actual response time ${end - start}`) + t.end(err) + }) +}) + test('POST /', (t) => { const max = 10 t.plan(max * 3) @@ -34,3 +46,16 @@ test('POST /', (t) => { }) } }) + +test('POST /posts?delay=100', (t) => { + const start = Date.now() + request(app) + .post('/posts?delay=100') + .send({ body: 'foo' }) + .expect(201, (err) => { + const end = Date.now() + t.assert(end - start >= 100, `actual response time ${end - start}`) + t.assert(end - start < 200, `actual response time ${end - start}`) + t.end(err) + }) +})