Skip to content

Commit

Permalink
docs: document fileExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 10, 2024
1 parent ad6a8e3 commit 7502e47
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ 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:
- `diff`: options for [`jest-diff`](https://github.com/facebook/jest/tree/master/packages/jest-diff)
- `fileExtension`: optional file extension to use for the snapshot file.

You should also [exclude the output files from Jest's watcher](https://jestjs.io/docs/en/configuration#watchpathignorepatterns-arraystring) so that updating the snapshot doesn't re-run the tests again.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# this is a another test
6 changes: 6 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ it('matches content of file on disk without filename', () => {
expect(`# this is a another test`).toMatchFile();
});

it('matches content of file on disk with file extension', () => {
expect(`# this is a another test`).toMatchFile(undefined, {
fileExtension: '.md',
});
});

it('matches binary content of file on disk', () => {
expect(
fs.readFileSync(path.join(__dirname, 'minimal.pdf'), 'binary')
Expand Down

0 comments on commit 7502e47

Please sign in to comment.