Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 1.38 KB

typescript.md

File metadata and controls

58 lines (40 loc) · 1.38 KB

TypeScript

Translations: Español, Français, Italiano, Русский, 简体中文

AVA comes bundled with a TypeScript definition file. This allows developers to leverage TypeScript for writing tests.

Setup

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"
  }
}

Add tests

Create a test.ts file.

import test from 'ava';

async function fn() {
    return Promise.resolve('foo');
}

test(async (t) => {
    t.is(await fn(), 'foo');
});

Execute the tests

$ npm test