diff --git a/CHANGELOG.md b/CHANGELOG.md index 7034e6f..d19d256 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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_ diff --git a/README.md b/README.md index dac2283..23b6ef8 100644 --- a/README.md +++ b/README.md @@ -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.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"