Skip to content

Commit

Permalink
reposition test elements in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Jun 1, 2023
1 parent 43682c1 commit a3451e8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,19 @@ test('package, alias and local file mocks', async () => {
assert.strictEqual(cookup('breakfast'), '☕🥓🧂')
})

test('global import tree mocks —third param', async () => {
const { getFile } = await esmock('../src/main.js', {}, {
// mocks *every* fs.readFileSync inside the import tree
fs: { readFileSync: () => 'returned to 🌲 every caller in the tree' }
})

assert.strictEqual(getFile(), 'returned to 🌲 every caller in the tree')
})

test('global mocks fetch, Date, setTimeout etc', async () => {
// https://github.com/iambumblehead/esmock/wiki#call-esmock-globals
const Users = await esmock('../Users.js', {
// this nested-esmock will define '../req.js' for '../Users.js' only
// nested esmock defines 'fetch' at req.js' import tree *only*
'../req.js': await esmock('../req.js', {
import: {
// define globals, such as 'fetch', using the import namespace
Expand All @@ -82,15 +91,6 @@ test('global mocks fetch, Date, setTimeout etc', async () => {
assert.deepEqual(await Users.count(), 2)
})

test('global import tree mocks —third param', async () => {
const { getFile } = await esmock('../src/main.js', {}, {
// mocks *every* fs.readFileSync inside the import tree
fs: { readFileSync: () => 'returned to 🌲 every caller in the tree' }
})

assert.strictEqual(getFile(), 'returned to 🌲 every caller in the tree')
})

test('mocks "await import()" using esmock.p', async () => {
// using esmock.p, mock definitions are kept in cache
const doAwaitImport = await esmock.p('../awaitImportLint.js', {
Expand Down

0 comments on commit a3451e8

Please sign in to comment.