jest-fs

1.0.2 • Public • Published

jest-fs

Node.js fs module mock for Jest unit testing.

Requirements

  • Node.js > 12
  • Jest

Usage

First we need to create a __mocks__ folder and inside of the folder we must create a fs.js file with the content:

const fs = require('jest-fs');
module.exports = fs;

After that, when creating a unit test we need to add these lines in the top:

const fs = require('fs');

// Add this
jest.mock('fs');

describe('testing jest-fs', () => {

  it('should create a file', () => {
    fs.writeFileSync('path/to/file.txt', 'content');

    const files = fs.readdirSync('path/to');

    expect(files.length).toBe(1);
  });
});

Package Sidebar

Install

npm i jest-fs

Weekly Downloads

103

Version

1.0.2

License

ISC

Unpacked Size

4.55 kB

Total Files

6

Last publish

Collaborators

  • leonardomaier