jest-fs-mock

0.0.1 • Public • Published

jest-mock-fs

Node's fs mock for jest.

APIs Implemented

  • [x] fs.readFileSync
  • [x] fs.readdirSync
  • [x] fs.writeFileSync
  • [x] fs.readFile
  • [x] fs.readdir
  • [x] fs.writeFile
  • [ ] fs.stat
  • [ ] fs.unlink
  • [ ] fs.mkdir
  • [ ] fs.rmdir

Setup

Step 1: Install library

npm i --save-dev jest-mock-fs

Step 2: Create a mock and re-export library Inside your tests/__mocks__/fs.js

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

Step 3: Add mock Inside your tests/example.test.js

jest.mock('fs');
View Full example.test.js file
const fs = require('fs');
jest.mock('fs');

test('should return content', async () => {
  // This will not create an actual file in your file system
  fs.writeFileSync('test.txt', 'test');
  const content = fs.readFileSync('test.txt', 'utf-8');
  expect(content).toBe('test');
});

Readme

Keywords

none

Package Sidebar

Install

npm i jest-fs-mock

Weekly Downloads

5

Version

0.0.1

License

ISC

Unpacked Size

2.31 kB

Total Files

4

Last publish

Collaborators

  • saurabhdaware