Skip to content

Commit

Permalink
Add an example for await using
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Nov 9, 2023
1 parent c8298b5 commit 98898e0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/User-Agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ user-agent object.
.textUnlike('head > title', /Bye/);
```

Testing WebSockets is almost as easy, but all operations are async and have to return a `Promise`.
Testing WebSockets is almost as easy, but all operations are async and have to return a `Promise`.

```js
await ua.websocketOk('/echo');
Expand All @@ -398,6 +398,22 @@ await ua.closeOk(4000);
await ua.closedOk(4000);
```

If you're using TypeScript we also support explicit resource management with `await using` for a little less
boilerplate.

```ts
import {app} from '../index.js';
import t from 'tap';

t.test('Example application', async t => {
await using ua = await app.newTestUserAgent({tap: t});

await t.test('Index', async t => {
(await ua.getOk('/')).statusIs(200).bodyLike(/mojo.js/);
});
});
```

And while the test user-agent is very efficient for testing backend services, for frontend testing we recommend
combining it with [playwright](https://www.npmjs.com/package/playwright).

Expand Down

0 comments on commit 98898e0

Please sign in to comment.