Browse Source

Close #589 PR: Add TypeScript recipe.

babel-plugin-for-integration-tests
Sam Verschueren 9 years ago
committed by Sindre Sorhus
parent
commit
20c66fe0ac
  1. 56
      docs/recipes/typescript.md
  2. 2
      readme.md

56
docs/recipes/typescript.md

@ -0,0 +1,56 @@
# TypeScript
AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.
## Setup
First install the TypeScript compiler [tsc](https://github.com/Microsoft/TypeScript).
```
$ npm install --save-dev tsc
```
Create a [`tsconfig.json`](https://github.com/Microsoft/TypeScript/wiki/tsconfig.json) file. This file specifies the compiler options required to compile the project or the test file.
```json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015"
}
}
```
Add a `test` script in the `package.json` file. It will compile the project first and then run AVA.
```json
{
"scripts": {
"test": "tsc && ava"
}
}
```
## Add tests
Create a `test.ts` file.
```ts
import test from 'ava';
async function fn() {
return Promise.resolve('foo');
}
test(async (t) => {
t.is(await fn(), 'foo');
});
```
## Execute the tests
```
$ npm test
```

2
readme.md

@ -699,7 +699,7 @@ AVA, not Ava or ava. Pronounced [`/ˈeɪvə/` ay-və](media/pronunciation.m4a?ra
- [Endpoint testing](docs/recipes/endpoint-testing.md)
- [When to use `t.plan()`](docs/recipes/when-to-use-plan.md)
- [Browser testing](docs/recipes/browser-testing.md)
- [TypeScript](docs/recipes/typescript.md)
## Support

Loading…
Cancel
Save