Skip to content

Commit ec04095

Browse files
Merge pull request #278 from iambumblehead/add-typescript-example-to-README
add typescript example to README
2 parents d40c0ca + c21bba0 commit ec04095

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* 2.6.1 _???.??.2023_
44
* [update README to work w/ eslint-plugin-markdown](https://github.com/iambumblehead/esmock/pull/275)
55
* [update eslint](https://github.com/iambumblehead/esmock/pull/276) disallow trailing whitespace
6+
* [add typescript example](https://github.com/iambumblehead/esmock/pull/278) to README
67
* 2.6.0 _Nov.07.2023_
78
* [typings: make MockFunction generic,](https://github.com/iambumblehead/esmock/pull/267) thanks @uwinkelvos
89
* 2.5.9 _Nov.01.2023_

README.md

+19
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ test('esmock.strict mocks', async () => {
9090
})
9191
```
9292

93+
`esmock` examples in typescript
94+
```ts
95+
import test from 'node:test'
96+
import assert from 'node:assert'
97+
import esmock from 'esmock'
98+
import type Rabbit from '../rabbit.js'
99+
100+
test('specify the type of export returned', async () => {
101+
const rabbit = await esmock<Rabbit>('../rabbit.js', {
102+
'../util.js': {
103+
multiply: (numbers: number[]): number => (
104+
numbers.reduce((acc, n) => acc *= n, 1))
105+
}
106+
})
107+
108+
assert.equal(rabbit.makebabies(), '🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇')
109+
})
110+
```
111+
93112
[0]: https://www.bumblehead.com "bumblehead"
94113
[1]: https://github.com/iambumblehead/esmock/workflows/nodejs-ci/badge.svg "nodejs-ci pipeline"
95114
[2]: https://github.com/iambumblehead/esmock "esmock"

0 commit comments

Comments
 (0)