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 @@
With any request, add a delay=N query string parameter to simulate a slow-running API response.
+ You can simulate a delay by adding a + delay query parameter (measured in milliseconds) to any route. +
++ 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) + }) +})