From da976d5b67080279f3b7535faa5ee520201a58b9 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 14 Nov 2023 02:45:41 -0800 Subject: [PATCH 1/3] add typescript example to README --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index dac2283..69e7f5a 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({ pairs: 3 }), '🐇🐇🐇🐇🐇🐇🐇') +}) +``` + [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" From 94fa215e2b6f2c80ec92de86a43bf2a19687a3c2 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 14 Nov 2023 02:47:50 -0800 Subject: [PATCH 2/3] add PR link to CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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_ From c21bba0d1bcf7ff2595e6f9027adbfd7b2bdd92f Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 14 Nov 2023 02:50:47 -0800 Subject: [PATCH 3/3] udpate README example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69e7f5a..23b6ef8 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ test('specify the type of export returned', async () => { } }) - assert.equal(rabbit.makebabies({ pairs: 3 }), '🐇🐇🐇🐇🐇🐇🐇') + assert.equal(rabbit.makebabies(), '🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇🐇') }) ```