Skip to content

Commit

Permalink
feat: first working implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 20, 2022
1 parent 9d15836 commit dc7e44f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
28 changes: 22 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# @japa/expect-type
> Write assertions for TypeScript types
<br />

<div align="center">

[![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]

</div>

The `expect-type` plugin of Japa helps you write assertions against the TypeScript types. There is no runtime behavior with the `expect-type` plugin and you need to compile your code to view the assertion errors.

The plugins wraps [expect-type](https://www.npmjs.com/package/expect-type) under the hood.

#### [Complete API documentation](https://japa.dev/docs/plugins/expect-type)

## Installation
Install the package from the npm registry as follows:

Expand All @@ -22,6 +18,26 @@ npm i @japa/expect-type
yarn add @japa/expect-type
```

## Usage
You can use this package with the `@japa/runner` as follows.

```ts
import { expectTypeOf } from '@japa/expect-type'
import { configure } from '@japa/runner'

configure({
plugins: [expectTypeOf()]
})
```

Once done, you will be able to access the `expectTypeOf` property on the test context.

```ts
test('test title', ({ expectTypeOf }) => {
expectTypeOf({ foo: 'bar' }).toEqualTypeOf<{ foo: string }>()
})
```

[gh-workflow-image]: https://img.shields.io/github/workflow/status/japa/expect-type/test?style=for-the-badge
[gh-workflow-url]: https://github.com/japa/expect-type/actions/workflows/test.yml "Github action"

Expand Down
23 changes: 23 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* @japa/expect-type
*
* (c) Japa
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import type { PluginFn } from '@japa/runner'
import { expectTypeOf as expectType } from 'expect-type'

export function expectTypeOf(): PluginFn {
return function (_, __, { TestContext }) {
TestContext.getter('expectType', () => expectType, true)
}
}

declare module '@japa/runner' {
interface TestContext {
expectType: typeof expectType
}
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
"prettier": "^2.7.1",
"typescript": "^4.7.3"
},
"peerDependencies": {
"@japa/runner": "^2.0.9"
},
"dependencies": {
"expect-type": "^0.14.2"
},
Expand Down

0 comments on commit dc7e44f

Please sign in to comment.