Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import * as diff from "diff"
export function chars(
actual: string,
expected: string,
message = "mismatching strings"
message = "mismatching strings",
options?: diff.BaseOptions
) {
if (actual == null) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (expected == null) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffChars(expected, actual)
const differences = diff.diffChars(expected, actual, options)
if (differences.length > 1) {
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
}
Expand All @@ -30,17 +31,18 @@ export function chars(
* @throws a bash-colored error if the arguments are not equal
*/
export function json(
actual: Record<string, unknown> | string[],
expected: Record<string, unknown> | string[],
message = "mismatching objects"
actual: object | string,
expected: object | string,
message = "mismatching objects",
options?: diff.JsonOptions
) {
if (!actual) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (!expected) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffJson(expected, actual)
const differences = diff.diffJson(expected, actual, options)
if (differences.length > 1) {
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
}
Expand All @@ -55,15 +57,16 @@ export function json(
export function trimmedLines(
actual: string,
expected: string,
message = "mismatching lines"
message = "mismatching lines",
options?: diff.LinesOptions
) {
if (actual == null) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (expected == null) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffTrimmedLines(expected, actual)
const differences = diff.diffTrimmedLines(expected, actual, options)
if (differences.length > 1) {
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
}
Expand All @@ -78,15 +81,16 @@ export function trimmedLines(
export function wordsWithSpace(
actual: string,
expected: string,
message = "mismatching words"
message = "mismatching words",
options?: diff.WordsOptions
) {
if (actual == null) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (expected == null) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffWordsWithSpace(expected, actual)
const differences = diff.diffWordsWithSpace(expected, actual, options)
if (differences.length > 1) {
throw new Error(`${message}:\n\n${renderDiff(differences)}`)
}
Expand Down