Tuz
Tuz

Reputation: 1980

mock fs failed with jest: " no such file or directory, lstat" , and mock_fs_1.default is not a function

I have a config file that I load with jest and I am trying to use mock-fs library to create a folder for an integration test

I got this error:

no such file or directory, lstat : 'path to one of another folder in the current directory '

and also I got this :

TypeError: mock_fs_1.default is not a function

in my config file that I Load to jest, I also bring the following library:

import * as getPort from 'get-port';
import { mockServerClient } from 'mockserver-client';
import * as mockServerNode from 'mockserver-node';
import mockfs from 'mock-fs';


 mockfs({
    'path/to/fake/dir': {
      'some-file.txt': 'file content here',
    },
});

Upvotes: 5

Views: 2767

Answers (2)

Ido Bar Lev
Ido Bar Lev

Reputation: 506

Managed to solve a similar issue based on the comments that I saw on this discussion:

As suggested add this line before calling the mockfs function:

console = new Console(process.stdout, process.stderr)

Of course, restore:

afterEach(() => {
    mockFs.restore();
});

Upvotes: 0

Eduard Jacko
Eduard Jacko

Reputation: 2151

This is due to mocked fs which jest is trying to use. You need to restore original fs after each test

import * as getPort from 'get-port';
import { mockServerClient } from 'mockserver-client';
import * as mockServerNode from 'mockserver-node';
import mockfs from 'mock-fs';

afterEach(() => {
  mockfs.restore();
})

 mockfs({
    'path/to/fake/dir': {
      'some-file.txt': 'file content here',
    },
});

Upvotes: 3

Related Questions