Questions tagged [mock-fs]
4 questions
1
vote
0 answers
const mock = require('mock-fs'); gives "TypeError: Cannot read properties of undefined (reading 'read')"
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 =…

AncientSwordRage
- 7,086
- 19
- 90
- 173
1
vote
0 answers
Why are dynamic imports unexpectedly coupled between tests when using mock-fs?
I'm trying to use mock-fs to unit test code which uses ES6 dynamic imports.
There seems to be an unexpected coupling between tests when I'm using dynamic imports, even though I call restore() after each test. It appears as though fs.readFile()…

mtmacdonald
- 14,216
- 19
- 63
- 99
0
votes
1 answer
How to Mock non-existent file import in nodejs Lambda
I am facing issue in testing where My logger is in lambda layer thus non-existing for nodeJs import in lambda.js during mocha-chai testing. I tried mock-fs but getting errors Can not find module /opt/logger.js or maybe I am trying wrong way and not…

Vishvendra Singh
- 484
- 5
- 19
0
votes
1 answer
Testing async fs.readfile with Jest and mock-fs has the tests timing out, even with 30 second time out
I have a function that reads the contents of a file from the file system asynchronously using Node's fs. While the function works, I cannot test it with Jest. I am using the mock-fs library to mock the file system to try to test the function.
The…

Steven Scott
- 10,234
- 9
- 69
- 117