Skip to content

Commit

Permalink
Update TypeScript recipe for mocks, Node.js 20
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell authored Jul 31, 2023
1 parent f047694 commit f2726f1
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions docs/recipes/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,44 @@ There are two components to a setup like this:

```json
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
]
}
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=tsx"
]
}
```
### When using custom loaders

#### Mocking

Mocking with `tsx` (such as with [`esmock`](https://github.com/iambumblehead/esmock)) isn't currently possible (https://github.com/esbuild-kit/tsx/issues/264). [`ts-node`](https://github.com/TypeStrong/ts-node) can be used instead:

`package.json`:

```json
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm",
"--loader=esmock"
]
}
```

#### Node.js 20

In Node.js 20, custom loaders must be specified via the `NODE_OPTIONS` environment variable:

`package.json`:

```json
"scripts": {
"test": "NODE_OPTIONS='--loader=tsx' ava"
}
```

## Writing tests
Expand Down

0 comments on commit f2726f1

Please sign in to comment.