Bug: Using mock-fs in beforeEach hooks breaks console.log()s
See original GitHub issueFor some reason, using mock-fs in beforeEach()
hooks causes all calls to console.log
in it()
functions to throw a ENOENT, no such file or directory '/path/to/project/node_modules/callsites'
error.
const mock = require("mock-fs");
describe("tests", () => {
beforeEach(() => {
mock({
"/foo/bar": {}
});
});
afterEach(() => {
mock.restore();
});
it("should fail", () => {
console.log(`This console.log will cause an error`);
});
});
envinfo:
System:
OS: macOS Sierra 10.12.6
CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 8.4.0
Yarn: 1.3.2
npm: 5.6.0
npmPackages:
jest:
wanted: ^22.4.2
installed: 22.4.2
Reproduction repo: https://github.com/AriaMinaei/jest-mock-fs-bug
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (2 by maintainers)
Top Results From Across the Web
mock-fs test fails in jest when console.log - Stack Overflow
For some strange reason when I try to console.log within a jest test using mock-fs it fails, I have no clue why this...
Read more >How to Test a Node.js Command-Line Tool | by Yeyan
For example, with the beforeEach hook, the code is mocked before each test case is run, and after it is finished, it is...
Read more >@gvhinks/search-github NPM | npm.io
Check @gvhinks/search-github 1.0.1 package - Last release 1.0.1 with GPL-3.0 ... 2 months │ Bug: Using mock-fs in beforeEach hooks breaks console.log()s ......
Read more >mock-fs - npm
mock-fs. The mock-fs module allows Node's built-in fs module to be backed temporarily by an in-memory, mock file system.
Read more >@jest/fake-timers | Yarn - Package Manager
npm version Jest is released under the MIT license. Follow on Twitter. GitHub CI Status Coverage Status. Gitpod ready-to-code ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems to me that calling
console.log
just before callingmock-fs
is a workaround. https://github.com/nknapp/jest-mock-fs-bughappends on most recent jest@24