-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENOENT: no such file or directory, open '/private/var/folders/ #364
Comments
@YonatanKra Did you manage to somehow solve this issue? I’m just doing
as it says in the docs and getting the same error. Tried different node versions and package versions, too, but nothing changed. Thanks in advance! |
I am leaving this here for anyone who needs it in the future. My testing says that you need to turn off the mocking between tests because Jest can't do its own internal logging. That's the best reason I can come up with anyway. Info in the README You also need to turn off the mocking if you're doing anything with snapshots. The README has this information at the bottom. import * as mockFs from 'mock-fs';
describe('your test', () => {
beforeEach(() => {
mockFs({
// Mocked file system
});
});
afterEach(() => {
mockFs.restore();
});
// Your tests
}); |
Hello @YonatanKra an @mixn , All files created with mock-fs using relative paths are relative to So, ensure you want to create the file in the current working directory (which in this case will be the root folder where a nodejs process is created from to run your tests). Or use import * as mockFs from 'mock-fs';
import path from 'path';
describe('your test', () => {
beforeEach(() => {
const rootPublicFolderPath = path.join(__dirname, '..', 'public')
mockFs({
'path/to/file.txt': 'file content here',
[rootPublicFolderPath]: mockFs.directory({
items: {
'my-file.txt': 'hello world'
}
})
});
});
afterEach(() => {
mockFs.restore();
});
test('test reading a file', () => {
const file = fs.readFileSync(`${process.cwd()}\path\to\file.txt`)
})
}); |
Using
mock-fs
gives me the following error:The stack trace is:
Any idea what can cause that?
The text was updated successfully, but these errors were encountered: