Skip to content

Commit

Permalink
update README example
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Aug 28, 2022
1 parent 9df2bc7 commit 7edb465
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"plugins": [],
"ignorePatterns": ["dist"],
"extends": [
"eslint:recommended",
"plugin:markdown/recommended"
Expand Down
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,20 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import esmock from 'esmock'

test('should mock local files and packages', async () => {
const stringy = await esmock('../src/stringy.js', {
stringifierpackage: JSON.stringify,
'#icons': { kasa: '' },
'../src/hello.js': {
default: () => 'world',
exportedFunction: () => ({ icon: 'kasa' })
test('should mock packages and local files', async () => {
const cookup = await esmock('../src/cookup.js', {
addpkg: (a, b) => a + b,
'#icon': {
coffee: '',
bacon: '🥓'
},
'../src/breakfast.js': {
default: () => ['coffee', 'bacon'],
addSalt: meal => meal + '🧂'
}
})

assert.strictEqual(stringy(), JSON.stringify({ kasa: 'world ☂' }))
assert.strictEqual(cookup('breakfast'), '☕🥓🧂')
})

test('should do global instance mocks —third param', async () => {
Expand All @@ -84,7 +87,7 @@ test('should mock "await import()" using esmock.p', async () => {

// mock definition is returned from cache, when import is called
assert.strictEqual(await doAwaitImport('cfg'), 'cfg')
// a bit more info are found in the descriptive guide
// a bit more info are found in the wiki guide
})

// a "partial mock" merges the new and original definitions
Expand Down

0 comments on commit 7edb465

Please sign in to comment.