Skip to content

Commit 952999d

Browse files
committed
feat: add an option to customize diff method. closes #25
1 parent fbeb739 commit 952999d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const isEqual = (a, b) => {
2424
* @param {string} [filepath] Path to the file to match against
2525
* @param {{
2626
* diff?: import('jest-diff').DiffOptions,
27+
* diffMethod?: (a: string, b: string, options: import('jest-diff').DiffOptions) => string,
2728
* fileExtension?: string,
2829
* }} options
2930
* @this {{ testPath: string, currentTestName: string, assertionCalls: number, isNot: boolean, snapshotState: { added: number, updated: number, unmatched: number, _updateSnapshot: 'none' | 'new' | 'all' } }}
@@ -116,10 +117,11 @@ exports.toMatchFile = function toMatchFile(content, filepath, options = {}) {
116117
} else {
117118
snapshotState.unmatched++;
118119

120+
const diffMethod = options.diffMethod || diff;
119121
const difference =
120122
Buffer.isBuffer(content) || Buffer.isBuffer(output)
121123
? ''
122-
: `\n\n${diff(output, content, options.diff)}`;
124+
: `\n\n${diffMethod(output, content, options.diff)}`;
123125

124126
return {
125127
pass: false,

0 commit comments

Comments
 (0)