Skip to content

Commit

Permalink
Enrich the docs when it comes to types
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-hritani committed Nov 10, 2023
1 parent cbe83c1 commit fd55874
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ test('full import tree mocks —third param', async () => {
assert.equal(getFile(), 'returned to 🌲 every caller in the tree')
})

import type * as utilsType from '../src/utils.js/';
test('allows you to specify the type of returned exports', async () => {
const { multiplyNumbers } = await esmock<typeof utilsType>(
'../src/utils.js', {
multiplyNumbers: (numbers: number[]): number => numbers.reduce((acc, current) => acc *= current, 1),
})

assert.equal(multiplyNumbers([1, 2, 3]), 6)
})

test('mock fetch, Date, setTimeout and any globals', async () => {
// https://github.com/iambumblehead/esmock/wiki#call-esmock-globals
const { userCount } = await esmock('../Users.js', {
Expand Down

0 comments on commit fd55874

Please sign in to comment.