Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update README example #132

Merged
merged 1 commit into from
Aug 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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