Comparing version 2.3.0 to 2.3.1
{ | ||
"name": "esmock", | ||
"type": "module", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"license": "ISC", | ||
"readmeFilename": "README.md", | ||
"description": "provides native ESM import mocking for unit tests", | ||
"description": "provides native ESM import and globals mocking for unit tests", | ||
"author": "chris <chris@bumblehead.com>", | ||
@@ -54,3 +54,6 @@ "main": "./src/esmock.js", | ||
"proxyquire", | ||
"rewire" | ||
"rewire", | ||
"global", | ||
"fetch", | ||
"mock fetch" | ||
], | ||
@@ -57,0 +60,0 @@ "engines": { |
@@ -12,3 +12,3 @@ ```diff | ||
**esmock provides native ESM import mocking for unit tests.** Use examples below as a quick-start guide, see the [descriptive and friendly esmock guide here,][4] or browse [esmock's test runner examples.][3] | ||
**esmock provides native ESM import and globals mocking for unit tests.** Use examples below as a quick-start guide, see the [descriptive and friendly esmock guide here,][4] or browse [esmock's test runner examples.][3] | ||
@@ -68,18 +68,27 @@ | ||
test('global mocks fetch, Date, setTimeout etc', async () => { | ||
const reqUsers = await esmock('../reqUsers.js', { | ||
import: { // define the 'fetch' mock, see wiki for more info | ||
fetch: () => '[["jim","π"],["jen","π"]]' | ||
} | ||
test('full 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(await reqUsers(), '[["jim","π"],["jen","π"]]') | ||
assert.strictEqual(getFile(), 'returned to π² every caller in the tree') | ||
}) | ||
test('global instance mocks βthird param', async () => { | ||
const { getFile } = await esmock('../src/main.js', {}, { | ||
fs: { readFileSync: () => 'returns this π globally' } | ||
test('mock fetch, Date, setTimeout and any globals', async () => { | ||
// https://github.com/iambumblehead/esmock/wiki#call-esmock-globals | ||
const Users = await esmock('../Users.js', { | ||
// 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 | ||
fetch: async () => ({ | ||
status: 200, | ||
json: async () => [["jim","π"],["jen","π"]] | ||
}) | ||
} | ||
}) | ||
}) | ||
assert.strictEqual(getFile(), 'returns this π globally') | ||
assert.deepEqual(await Users.count(), 2) | ||
}) | ||
@@ -86,0 +95,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19646
130