Skip to content

Commit

Permalink
Null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo committed Jul 19, 2019
1 parent 75c643b commit 930f81a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/index.ts
Expand Up @@ -10,10 +10,10 @@ export function chars(
expected: string,
message = "mismatching strings"
) {
if (!actual) {
if (actual == null) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (!expected) {
if (expected == null) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffChars(expected, actual)
Expand Down Expand Up @@ -53,10 +53,10 @@ export function trimmedLines(
expected: string,
message = "mismatching lines"
) {
if (!actual) {
if (actual == null) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (!expected) {
if (expected == null) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffTrimmedLines(expected, actual)
Expand All @@ -75,10 +75,10 @@ export function wordsWithSpace(
expected: string,
message = "mismatching words"
) {
if (!actual) {
if (actual == null) {
throw new Error("AssertNoDiff: actual value not provided")
}
if (!expected) {
if (expected == null) {
throw new Error("AssertNoDiff: expected value not provided")
}
const differences = diff.diffWordsWithSpace(expected, actual)
Expand Down
4 changes: 4 additions & 0 deletions test/chars-test.ts
Expand Up @@ -44,4 +44,8 @@ describe("assertNoDiff.chars", function() {
}
throw new Error("assertNoDiff.chars didn't throw")
})

it("allows diffing against empty strings", function() {
assertNoDiff.chars("", "")
})
})
3 changes: 3 additions & 0 deletions test/json-test.ts
Expand Up @@ -44,4 +44,7 @@ describe("assertNoDiff.json", function() {
}
throw new Error("assertNoDiff.json didn't throw")
})
it("allows diffing empty objects", function() {
assertNoDiff.json({}, {})
})
})
4 changes: 4 additions & 0 deletions test/trimmed-lines-test.ts
Expand Up @@ -51,4 +51,8 @@ describe("assertNoDiff.trimmedLines", function() {
}
throw new Error("assertNoDiff.trimmedLines didn't throw")
})

it("allows diffing against empty strings", function() {
assertNoDiff.trimmedLines("", "")
})
})
4 changes: 4 additions & 0 deletions test/words-with-space-test.ts
Expand Up @@ -56,4 +56,8 @@ describe("assertNoDiff.wordsWithSpace", function() {
}
throw new Error("assertNoDiff.wordsWithSpace didn't throw")
})

it("allows diffing against empty strings", function() {
assertNoDiff.wordsWithSpace("", "")
})
})

0 comments on commit 930f81a

Please sign in to comment.