diff --git a/README.md b/README.md index 1c69fc0..3fafd56 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/__tests__/__file_snapshots__/matches-content-of-file-on-disk-with-file-extension-0.md b/__tests__/__file_snapshots__/matches-content-of-file-on-disk-with-file-extension-0.md new file mode 100644 index 0000000..6942301 --- /dev/null +++ b/__tests__/__file_snapshots__/matches-content-of-file-on-disk-with-file-extension-0.md @@ -0,0 +1 @@ +# this is a another test \ No newline at end of file diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 585b3fd..67a7b25 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -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')