jest-diff
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
chalk | 4.1.2 | 11.31 kB | MIT | prod | |
diff-sequences | 29.6.3 | 11.14 kB | MIT | prod | |
jest-get-type | 29.6.3 | 1.72 kB | MIT | prod | |
pretty-format | 29.7.0 | 14.34 kB | MIT | prod |
Jest-diff is a JavaScript package providing valuable tools for comparing JavaScript values, strings, and arrays of strings. The package uses a special serialization technique to highlight differences in data points, allowing people to review modifications line-by-line or character-by-character confidently. Jest-diff is particularly handy during JavaScript testing, as it can be utilized to track changes and differences in the tested data.
To use the jest-diff package, firstly, you need to install it as a project dependency by running either npm install jest-diff
or yarn add jest-diff
.
The jest-diff package can be used for comparing a broad range of data types and structures:
import { diff } from 'jest-diff';
const a = ['delete', 'common', 'changed from'];
const b = ['common', 'changed to', 'insert'];
const difference = diff(a, b);
import { diffStringsUnified } from 'jest-diff';
const a = 'common\nchanged from';
const b = 'common\nchanged to';
const difference = diffStringsUnified(a, b);
import { diffLinesUnified } from 'jest-diff';
const aLines = ['delete', 'common', 'changed from'];
const bLines = ['common', 'changed to', 'insert'];
const difference = diffLinesUnified(aLines, bLines);
All these calls will return strings or arrays of Diff
objects representing differences in data.
Jest-diff's official documentation, containing detailed explanations and examples of all the described use cases and much more, is located at the main Jest documentation portal. Directly accessible from the package homepage on the npm and Yarn registry, you'll find a wealth of information on utilizing jest-diff efficiently.