Skip to content

Commit b4fd951

Browse files
authored
Expose all diff options (#77)
1 parent 6f1a269 commit b4fd951

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/index.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ import * as diff from "diff"
99
export function chars(
1010
actual: string,
1111
expected: string,
12-
message = "mismatching strings"
12+
message = "mismatching strings",
13+
options?: diff.BaseOptions
1314
) {
1415
if (actual == null) {
1516
throw new Error("AssertNoDiff: actual value not provided")
1617
}
1718
if (expected == null) {
1819
throw new Error("AssertNoDiff: expected value not provided")
1920
}
20-
const differences = diff.diffChars(expected, actual)
21+
const differences = diff.diffChars(expected, actual, options)
2122
if (differences.length > 1) {
2223
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
2324
}
@@ -30,17 +31,18 @@ export function chars(
3031
* @throws a bash-colored error if the arguments are not equal
3132
*/
3233
export function json(
33-
actual: Record<string, unknown> | string[],
34-
expected: Record<string, unknown> | string[],
35-
message = "mismatching objects"
34+
actual: object | string,
35+
expected: object | string,
36+
message = "mismatching objects",
37+
options?: diff.JsonOptions
3638
) {
3739
if (!actual) {
3840
throw new Error("AssertNoDiff: actual value not provided")
3941
}
4042
if (!expected) {
4143
throw new Error("AssertNoDiff: expected value not provided")
4244
}
43-
const differences = diff.diffJson(expected, actual)
45+
const differences = diff.diffJson(expected, actual, options)
4446
if (differences.length > 1) {
4547
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
4648
}
@@ -55,15 +57,16 @@ export function json(
5557
export function trimmedLines(
5658
actual: string,
5759
expected: string,
58-
message = "mismatching lines"
60+
message = "mismatching lines",
61+
options?: diff.LinesOptions
5962
) {
6063
if (actual == null) {
6164
throw new Error("AssertNoDiff: actual value not provided")
6265
}
6366
if (expected == null) {
6467
throw new Error("AssertNoDiff: expected value not provided")
6568
}
66-
const differences = diff.diffTrimmedLines(expected, actual)
69+
const differences = diff.diffTrimmedLines(expected, actual, options)
6770
if (differences.length > 1) {
6871
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
6972
}
@@ -78,15 +81,16 @@ export function trimmedLines(
7881
export function wordsWithSpace(
7982
actual: string,
8083
expected: string,
81-
message = "mismatching words"
84+
message = "mismatching words",
85+
options?: diff.WordsOptions
8286
) {
8387
if (actual == null) {
8488
throw new Error("AssertNoDiff: actual value not provided")
8589
}
8690
if (expected == null) {
8791
throw new Error("AssertNoDiff: expected value not provided")
8892
}
89-
const differences = diff.diffWordsWithSpace(expected, actual)
93+
const differences = diff.diffWordsWithSpace(expected, actual, options)
9094
if (differences.length > 1) {
9195
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
9296
}

0 commit comments

Comments
 (0)