Skip to content

Commit

Permalink
feat: add an option to customize diff method. closes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 10, 2024
1 parent fbeb739 commit 952999d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const isEqual = (a, b) => {
* @param {string} [filepath] Path to the file to match against
* @param {{
* diff?: import('jest-diff').DiffOptions,
* diffMethod?: (a: string, b: string, options: import('jest-diff').DiffOptions) => string,
* fileExtension?: string,
* }} options
* @this {{ testPath: string, currentTestName: string, assertionCalls: number, isNot: boolean, snapshotState: { added: number, updated: number, unmatched: number, _updateSnapshot: 'none' | 'new' | 'all' } }}
Expand Down Expand Up @@ -116,10 +117,11 @@ exports.toMatchFile = function toMatchFile(content, filepath, options = {}) {
} else {
snapshotState.unmatched++;

const diffMethod = options.diffMethod || diff;
const difference =
Buffer.isBuffer(content) || Buffer.isBuffer(output)
? ''
: `\n\n${diff(output, content, options.diff)}`;
: `\n\n${diffMethod(output, content, options.diff)}`;

return {
pass: false,
Expand Down

0 comments on commit 952999d

Please sign in to comment.