From fc269b65cae0e61e1538d7c432538093894bbe20 Mon Sep 17 00:00:00 2001 From: Jack Tomaszewski Date: Thu, 8 Apr 2021 08:58:57 +1000 Subject: [PATCH] docs: Add async/await example to README --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 66330216..ef12e204 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,21 @@ describe('GET /users', function() { }); ``` +Or async/await syntax: + +```js +describe('GET /users', function() { + it('responds with json', async function() { + const response = request(app) + .get('/users') + .set('Accept', 'application/json') + expect(response.headers["Content-Type"]).toMatch(/json/); + expect(response.status).toEqual(200); + expect(response.body.email).toEqual('foo@bar.com'); + }); +}); +``` + Expectations are run in the order of definition. This characteristic can be used to modify the response body or headers before executing an assertion.