Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More β†’
Socket
Sign inDemoInstall
Socket

esmock

Package Overview
Dependencies
Maintainers
1
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esmock - npm Package Compare versions

Comparing version 2.3.0 to 2.3.1

9

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc