Here is the full error output:
Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'read')
2 | const { default: axios } = require('axios');
3 | const fs = require('fs');
> 4 | const mockFs = require('mock-fs');
The module mock-fs is definitely installed, and I have deleted node_modules and reinstalled...
I am using VSCode on WSL1.
How do I import mock-fs?
This is due to running:
before it runs the mock.
If you do, then the process that mock-fs uses to fetch the readContext no longer works:
This is within readfilecontext.js
After that's run, the fsBinding.open is never called (due to the fs.readFile being mocked, and the readFileContext always stays undefined.
This is happening to me using jest + typescript + mock-fs on es6 module mode. When I was using commonjs without typescript, it ran with the
jest.mock('fs')just fine.