You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@
12
12
-`[jest-diff]`[**BREAKING**] Export as ECMAScript module ([#8873](https://github.com/facebook/jest/pull/8873))
13
13
-`[jest-diff]` Add `includeChangeCounts` and rename `Indicator` options ([#8881](https://github.com/facebook/jest/pull/8881))
14
14
-`[jest-diff]` Add `changeColor` and `patchColor` options ([#8911](https://github.com/facebook/jest/pull/8911))
15
+
-`[jest-diff]` Add `trailingSpaceFormatter` option and replace cyan with `commonColor` ([#8927](https://github.com/facebook/jest/pull/8927))
@@ -196,7 +196,7 @@ To write a **formatting** function, you might need the named constants (and `Dif
196
196
If you write an application-specific **cleanup** algorithm, then you might need to call the `Diff` constructor:
197
197
198
198
```js
199
-
constdiffCommon=newDiff(DIFF_EQUAL, 'change');
199
+
constdiffCommon=newDiff(DIFF_EQUAL, 'changed');
200
200
constdiffDelete=newDiff(DIFF_DELETE, 'from');
201
201
constdiffInsert=newDiff(DIFF_INSERT, 'to');
202
202
```
@@ -207,27 +207,30 @@ The default options are for the report when an assertion fails from the `expect`
207
207
208
208
For other applications, you can provide an options object as a third argument:
209
209
210
-
-`diffLinesUnified(a, b, options)`
210
+
-`diffDefault(a, b, options)`
211
211
-`diffStringsUnified(a, b, options)`
212
212
213
213
### Properties of options object
214
214
215
-
| name | default |
216
-
| :-------------------- | :-------------- |
217
-
|`aAnnotation`|`'Expected'`|
218
-
|`aColor`|`chalk.green`|
219
-
|`aIndicator`|`'-'`|
220
-
|`bAnnotation`|`'Received'`|
221
-
|`bColor`|`chalk.red`|
222
-
|`bIndicator`|`'+'`|
223
-
|`changeColor`|`chalk.inverse`|
224
-
|`commonColor`|`chalk.dim`|
225
-
|`commonIndicator`|`' '`|
226
-
|`contextLines`|`5`|
227
-
|`expand`|`true`|
228
-
|`includeChangeCounts`|`false`|
229
-
|`omitAnnotationLines`|`false`|
230
-
|`patchColor`|`chalk.yellow`|
215
+
| name | default |
216
+
| :----------------------- | :--------------- |
217
+
|`aAnnotation`|`'Expected'`|
218
+
|`aColor`|`chalk.green`|
219
+
|`aIndicator`|`'-'`|
220
+
|`bAnnotation`|`'Received'`|
221
+
|`bColor`|`chalk.red`|
222
+
|`bIndicator`|`'+'`|
223
+
|`changeColor`|`chalk.inverse`|
224
+
|`commonColor`|`chalk.dim`|
225
+
|`commonIndicator`|`' '`|
226
+
|`contextLines`|`5`|
227
+
|`expand`|`true`|
228
+
|`includeChangeCounts`|`false`|
229
+
|`omitAnnotationLines`|`false`|
230
+
|`patchColor`|`chalk.yellow`|
231
+
|`trailingSpaceFormatter`|`chalk.bgYellow`|
232
+
233
+
For more information about the options, see the following examples.
231
234
232
235
### Example of options for labels
233
236
@@ -240,6 +243,15 @@ const options = {
240
243
};
241
244
```
242
245
246
+
```diff
247
+
- Original
248
+
+ Modified
249
+
250
+
- changed from
251
+
+ changed to
252
+
common
253
+
```
254
+
243
255
The `jest-diff` package does not assume that the 2 labels have equal length.
244
256
245
257
### Example of options for colors of changed lines
@@ -257,29 +269,46 @@ const options = {
257
269
258
270
### Example of option for color of changed substrings
259
271
260
-
Although the default inverse of foreground and background colors is hard to beat for changed substrings **within lines**, especially because it highlights spaces, if you want bold font weight on yellow background:
272
+
Although the default inverse of foreground and background colors is hard to beat for changed substrings **within lines**, especially because it highlights spaces, if you want bold font weight on yellow background color:
261
273
262
274
```js
275
+
importchalkfrom'chalk';
276
+
263
277
constoptions= {
264
278
changeColor:chalk.bold.bgAnsi256(226), // #ffff00
265
279
};
266
280
```
267
281
282
+
### Example of option to format trailing spaces
283
+
284
+
Because the default export does not display substring differences within lines, formatting can help you see when lines differ by the presence or absence of trailing spaces found by `/\s+$/` regular expression.
285
+
286
+
The formatter is a function, which given a string, returns a string.
287
+
288
+
If instead of yellowish background color, you want to replace trailing spaces with middle dot characters:
0 commit comments