• Version 4.13.4
  • Published
  • 14.1 kB
  • 1 dependency
  • MIT license


npm i @types/mock-fs
yarn add @types/mock-fs
pnpm add @types/mock-fs


TypeScript definitions for mock-fs



function bypass

bypass: <T>(fn: () => T) => T;
  • Temporarily bypass the mocked file system and load directly from the real file system.

    Example 1

    const filePath = '/path/file.json'; const data = mock.bypass(() => fs.readFileSync(filePath, 'utf-8'));

function directory

directory: (config?: FileSystem.DirectoryOptions) => () => Directory;
  • Create a directory factory.

function file

file: (config?: FileSystem.FileOptions) => () => File;
  • Create a file factory.

function getMockRoot

getMockRoot: () => Directory | {};
  • Get hold of the mocked filesystem's 'root' If fs hasn't currently been replaced, this will return an empty object

function load

load: (
path: string,
options?: FileSystem.LoaderOptions
) => FileSystem.DirectoryItem;
  • Load a real file/folder into the mock file system.

function mock

mock: typeof mock;
  • Swap out the fs bindings for a mock file system.

    _Note:_ Import this file _before_ any other modules that import the fs module.

    Parameter config

    Mock file system configuration.

    Parameter options

    Any filesystem options.


    options.createCwd Create a directory for process.cwd() (defaults to true).


    options.createTmp Create a directory for os.tmpdir() (defaults to true).

function restore

restore: () => void;
  • Restore the fs bindings for the real file system.

symlink: (config: FileSystem.SymlinkOptions) => () => SymbolicLink;
  • Create a symbolic link factory.

Package Files (1)

Dependencies (1)

Dev Dependencies (0)

No dev dependencies.

Peer Dependencies (0)

No peer dependencies.


To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/mock-fs.

  • Markdown
  • HTML
    <a href="https://www.jsdocs.io/package/@types/mock-fs"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>