-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #589 PR: Add TypeScript recipe.
- Loading branch information
1 parent
5e02387
commit 20c66fe
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters