Skip to content

Instantly share code, notes, and snippets.

@JLHwung
Last active January 11, 2018 10:44
Show Gist options
  • Save JLHwung/281f004baa1c40f28cc444f8e49e604f to your computer and use it in GitHub Desktop.
Save JLHwung/281f004baa1c40f28cc444f8e49e604f to your computer and use it in GitHub Desktop.
integration issue with jest and mock-require

Usage

npm install
npx jest
const mock = require("mock-require");
mock.stopAll();
require = require("@std/esm")(module)
module.exports = require("./main.mjs").default
require("./index");
describe("foo", () => {
it("should work");
})
import path from "path"
{
"name": "playground",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"@std/esm": {
"cjs": true,
"cache": false
},
"dependencies": {
"@std/esm": "^0.19.1",
"mock-require": "^2.0.2"
},
"devDependencies": {
"jest": "^22.0.6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment