From 930f81a442169e9fbd76955252857625dc19c2e4 Mon Sep 17 00:00:00 2001 From: Kevin Goslar Date: Fri, 19 Jul 2019 10:29:20 -0500 Subject: [PATCH] Null checks --- src/index.ts | 12 ++++++------ test/chars-test.ts | 4 ++++ test/json-test.ts | 3 +++ test/trimmed-lines-test.ts | 4 ++++ test/words-with-space-test.ts | 4 ++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index f56d133..081465d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) @@ -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) @@ -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) diff --git a/test/chars-test.ts b/test/chars-test.ts index 7fc2b65..a64498b 100644 --- a/test/chars-test.ts +++ b/test/chars-test.ts @@ -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("", "") + }) }) diff --git a/test/json-test.ts b/test/json-test.ts index f10208e..afba28d 100644 --- a/test/json-test.ts +++ b/test/json-test.ts @@ -44,4 +44,7 @@ describe("assertNoDiff.json", function() { } throw new Error("assertNoDiff.json didn't throw") }) + it("allows diffing empty objects", function() { + assertNoDiff.json({}, {}) + }) }) diff --git a/test/trimmed-lines-test.ts b/test/trimmed-lines-test.ts index e464734..ea5c10b 100644 --- a/test/trimmed-lines-test.ts +++ b/test/trimmed-lines-test.ts @@ -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("", "") + }) }) diff --git a/test/words-with-space-test.ts b/test/words-with-space-test.ts index 232c1a7..aa7466c 100644 --- a/test/words-with-space-test.ts +++ b/test/words-with-space-test.ts @@ -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("", "") + }) })