Skip to content

Commit

Permalink
test: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Apr 14, 2024
1 parent f189159 commit 6880d4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions packages/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
```
2 changes: 1 addition & 1 deletion packages/unit/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface Test {

interface Assert extends Omit<typeof assert, 'CallTracker' | 'AssertionError' | 'strict'> {}

interface ExtendedTestContext extends Omit<TestContext, 'test'>, Assert {
export interface ExtendedTestContext extends Omit<TestContext, 'test'>, Assert {
plan: (count: number) => void
test: Test
}
Expand Down

0 comments on commit 6880d4d

Please sign in to comment.