Skip to content

targendaz2/jest-extended-fs

Repository files navigation

jest-extended-fs

GitHub License GitHub Release NPM Version GitHub Actions Workflow Status

This package adds file system matchers to Jest.

Installation

This package is available on npm as jest-extended-fs.

npm install -D jest jest-extended-fs

Set Up

Individual Matchers

In your Jest configuration file (e.g. jest.config.ts), for each matcher you want to enable, add the matcher to the setupFilesAfterEnv setting.

const config = {
    setupFilesAfterEnv = ['jest-extended-fs/matchers/toBeAFile.js']
};

All Matchers

Follow the "Individual Matchers" instructions above using jest-extended-fs instead of any specific matcher.

const config = {
    setupFilesAfterEnv = ['jest-extended-fs']
};

Matchers

Common Matchers

  • .toExist()

Directory Matchers

  • .toBeADirectory()
  • .toBeADirectoryContaining(contents)
  • .toBeAnEmptyDirectory()

File Matchers

  • .toBeAFile()
  • .toBeAFileContaining(text)
  • .toBeAnEmptyFile()
  • .toHaveMode(mode)
  • .toBeExecutable()

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This package is licensed under the MIT License.