diff --git a/packages/unit/README.md b/packages/unit/README.md index 6db68a03..48997ac3 100644 --- a/packages/unit/README.md +++ b/packages/unit/README.md @@ -26,3 +26,34 @@ test('test', (t) => { }) }) ``` + +### CLI + +This package provide a handy function to collect test +file and run it. + +```shell +# JavaScript +unit +# TypeScript +NODE_OPTIONS="--require ts-node/register" unit +``` + +### TypeScript + +Due to the limitation on TypeScript about `asserts`, +you need to explicitly type the context before using +some of the API. + +```ts +import { test, type ExtendedTestContext } from '@kakang/unit' + +test('context', (t: ExtendedTestContext) => { + t.ok('pass') // without explicit typing the `t`, it would fail +}) + +test('function', (t) => { + const ok: typeof t.ok = t.ok + ok('pass') // without explicit typing the `ok`, it would fail +}) +``` diff --git a/packages/unit/lib/index.ts b/packages/unit/lib/index.ts index 207acf56..ebc870b3 100644 --- a/packages/unit/lib/index.ts +++ b/packages/unit/lib/index.ts @@ -60,7 +60,7 @@ interface Test { interface Assert extends Omit {} -interface ExtendedTestContext extends Omit, Assert { +export interface ExtendedTestContext extends Omit, Assert { plan: (count: number) => void test: Test }