All Projects → satya164 → jest-file-snapshot

satya164 / jest-file-snapshot

Licence: other
Jest matcher to write snapshots to a separate file instead of the default snapshot file used by Jest

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to jest-file-snapshot

reducer-tester
Utilities for testing redux reducers
Stars: ✭ 19 (-45.71%)
Mutual labels:  jest, snapshot-testing
Snapshot Diff
Diffing snapshot utility for Jest
Stars: ✭ 490 (+1300%)
Mutual labels:  jest, snapshot-testing
GFontsSpace
Preview: https://pankajladhar.github.io/GFontsSpace
Stars: ✭ 88 (+151.43%)
Mutual labels:  jest, snapshot-testing
Enzyme To Json
Snapshot test your Enzyme wrappers
Stars: ✭ 954 (+2625.71%)
Mutual labels:  jest, snapshot-testing
Snapguidist
Snapshot testing for React Styleguidist
Stars: ✭ 287 (+720%)
Mutual labels:  jest, snapshot-testing
Typescript Snapshots Plugin
Snapshots language service support for Typescript
Stars: ✭ 122 (+248.57%)
Mutual labels:  jest, snapshot-testing
react-tools-for-better-angular-apps
Use React ecosystem for unified and top notch DX for angular developement
Stars: ✭ 30 (-14.29%)
Mutual labels:  jest
Splain
small parser to create more interesting language/sentences
Stars: ✭ 15 (-57.14%)
Mutual labels:  jest
nimbus
Centralized CLI for JavaScript and TypeScript developer tools.
Stars: ✭ 112 (+220%)
Mutual labels:  jest
rescript-jest
ReScript bindings for Jest
Stars: ✭ 274 (+682.86%)
Mutual labels:  jest
riteway-jest
Unit tests that always supply a good bug report when they fail for Jest.
Stars: ✭ 24 (-31.43%)
Mutual labels:  jest
xstate-marionettist
Model based testing with Jest, XState and Puppeteer or Playwright made easy
Stars: ✭ 23 (-34.29%)
Mutual labels:  jest
jest-playground
Playing around with Jest - Subscribe to my YouTube channel: https://bit.ly/CognitiveSurge
Stars: ✭ 24 (-31.43%)
Mutual labels:  jest
gobarber-api-gostack11
API GoBarber / NodeJS / Express / Typescript / SOLID
Stars: ✭ 39 (+11.43%)
Mutual labels:  jest
firestore-jest-mock
Jest Helper library for mocking Cloud Firestore
Stars: ✭ 128 (+265.71%)
Mutual labels:  jest
jest-snapshot-talk
React Conf 2017: Jest, Snapshots and Beyond
Stars: ✭ 48 (+37.14%)
Mutual labels:  jest
energy-use-case-trading-client
Energy Use Case Web UI for Lition Trading Platform
Stars: ✭ 23 (-34.29%)
Mutual labels:  jest
express-typeorm-rest-boilerplate
Boilerplate code to get started with building RESTful API Services (Express, TypeORM MongoDB stack)
Stars: ✭ 53 (+51.43%)
Mutual labels:  jest
fly-helper
It's a Tool library, method collection
Stars: ✭ 21 (-40%)
Mutual labels:  jest
gobarber-app
💈A BarberShop app made with React, React Native and Node.
Stars: ✭ 34 (-2.86%)
Mutual labels:  jest

jest-file-snapshot

Build Status Code Coverage MIT License Version

Jest matcher to write snapshots to a separate file instead of the default snapshot file used by Jest. Writing a snapshot to a separate file means you have proper syntax highlighting in the output file, and better readability without those pesky escape characters. It's also useful if you have binary content.

Installation

npm install --save-dev jest-file-snapshot

or

yarn add --dev jest-file-snapshot

Usage

Extend Jest's expect:

import { toMatchFile } from 'jest-file-snapshot';

expect.extend({ toMatchFile });

Then use it in your tests:

it('matches content of file on disk', () => {
  expect(content).toMatchFile();
});

The content passed can be of type string or a Buffer. The comparison be done using Buffer.equals() instead of === if a Buffer is passed.

The matcher takes two optional arguments:

  • filepath: path to the file whose content should be matched, e.g. expect(content).toMatchFile(path.join(__dirname, 'output.md'))
  • options: additional options object for the matcher, with following properties:

You should also exclude the output files from Jest's watcher so that updating the snapshot doesn't re-run the tests again.

For example, by default toMatchFile uses a folder named __file_snapshots__ which you can exclude by adding the following under the jest key in package.json:

"watchPathIgnorePatterns": [
  "__file_snapshots__"
]

Credits

Contributing

Make sure your code passes the unit tests, ESLint and TypeScript. Run the following to verify:

yarn test
yarn lint
yarn typescript

To fix formatting errors, run the following:

yarn lint -- --fix
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].