Translations: Español, Français, Italiano, Русский, 简体中文
AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.
First install TypeScript.
$ npm install --save-dev typescript
Create a tsconfig.json
file. This file specifies the compiler options required to compile the project or the test file.
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015"
}
}
Add a test
script in the package.json
file. It will compile the project first and then run AVA.
{
"scripts": {
"test": "tsc && ava"
}
}
Create a test.ts
file.
import test from 'ava';
async function fn() {
return Promise.resolve('foo');
}
test(async (t) => {
t.is(await fn(), 'foo');
});
$ npm test