jest-mock-fs

1.0.2 • Public • Published

jest-mock-fs

Github: https://github.com/tashes/jest-mock-fs

Install this package using:

npm install jest-mock-fs

This package will create a jest mock factory function to allow you to mock a filesystem while still being able to check mock calls. To use it, import it and call it like so:

const jestMockFs = require('jest-mock-fs');

var mockFs = jestMockFs({
    'folder': {
        'file.ext': "contents",
        'anotherfile.ext': new Buffer()
    },
    'file.txt': "othercontents"
});
jest.mock('fs', () => ({ ...mockFs }));

The following fs functions have been mocked till now:

  • [x] existsSync
    • _path_
  • [x] readFileSync
    • path
    • options
      • encoding
  • [x] writeFileSync
    • path
    • contents
    • options
        • encoding
  • [x] unlinkSync
    • path
  • [x] readdirSync
    • -path
  • [x] mkdirSync
    • path
  • [x] rmSync
    • path
    • options
      • force
      • recursive
      • maxRetries
      • retryDelay

Readme

Keywords

none

Package Sidebar

Install

npm i jest-mock-fs

Weekly Downloads

150

Version

1.0.2

License

ISC

Unpacked Size

48.9 kB

Total Files

29

Last publish

Collaborators

  • tamatashwin