Skip to content

Commit

Permalink
Close #589 PR: Add TypeScript recipe.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren authored and sindresorhus committed Mar 2, 2016
1 parent 5e02387 commit 20c66fe
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions docs/recipes/typescript.md
Original file line number Diff line number Diff line change
@@ -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 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 20c66fe

Please sign in to comment.