1.0.2 • Published 2 years ago

jest-fs v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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);
  });
});
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

2 years ago