Skip to content

Commit

Permalink
Merge pull request #278 from iambumblehead/add-typescript-example-to-…
Browse files Browse the repository at this point in the history
…README

add typescript example to README
  • Loading branch information
iambumblehead authored Nov 14, 2023
2 parents d40c0ca + c21bba0 commit ec04095
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* 2.6.1 _???.??.2023_
* [update README to work w/ eslint-plugin-markdown](https://github.com/iambumblehead/esmock/pull/275)
* [update eslint](https://github.com/iambumblehead/esmock/pull/276) disallow trailing whitespace
* [add typescript example](https://github.com/iambumblehead/esmock/pull/278) to README
* 2.6.0 _Nov.07.2023_
* [typings: make MockFunction generic,](https://github.com/iambumblehead/esmock/pull/267) thanks @uwinkelvos
* 2.5.9 _Nov.01.2023_
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ test('esmock.strict mocks', async () => {
})
```

`esmock` examples in typescript
```ts
import test from 'node:test'
import assert from 'node:assert'
import esmock from 'esmock'
import type Rabbit from '../rabbit.js'

test('specify the type of export returned', async () => {
const rabbit = await esmock<Rabbit>('../rabbit.js', {
'../util.js': {
multiply: (numbers: number[]): number => (
numbers.reduce((acc, n) => acc *= n, 1))
}
})

assert.equal(rabbit.makebabies(), '🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇')
})
```

[0]: https://www.bumblehead.com "bumblehead"
[1]: https://github.com/iambumblehead/esmock/workflows/nodejs-ci/badge.svg "nodejs-ci pipeline"
[2]: https://github.com/iambumblehead/esmock "esmock"
Expand Down

0 comments on commit ec04095

Please sign in to comment.