Skip to content

New function syntax #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
Show file tree
Hide file tree
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
20 changes: 10 additions & 10 deletions test/chars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,41 @@ import { suite, test } from "node:test"
import stripAnsi from "strip-ansi"
import * as assertNoDiff from "../src/index"

suite("assertNoDiff.chars()", function() {
test("matching data", function() {
suite("assertNoDiff.chars()", () => {
test("matching data", () => {
const data = "Jean-Luc Picard"
assertNoDiff.chars(data, data)
})

test("mismatching data", function() {
test("mismatching data", () => {
const obj1 = "Jean-Luc Picard"
const obj2 = "Captain Picard"
const expected = `mismatching strings:

${red("Je")}${green("C")}${gray("a")}${green("ptai")}${gray("n")}${red("-Luc")}${gray(" Picard")}`
assert.throws(
function() {
() => {
assertNoDiff.chars(obj2, obj1)
},
new Error(expected)
)
})

test("no expected value", function() {
assert.throws(function() {
test("no expected value", () => {
assert.throws(() => {
// @ts-ignore: intentional call without second argument
assertNoDiff.chars("foo")
}, new Error("AssertNoDiff: expected value not provided"))
})

test("no actual value", function() {
assert.throws(function() {
test("no actual value", () => {
assert.throws(() => {
// @ts-ignore: intentional call without arguments
assertNoDiff.chars()
}, new Error("AssertNoDiff: actual value not provided"))
})

test("providing a custom message", function() {
test("providing a custom message", () => {
try {
assertNoDiff.chars("one", "two", "custom message")
} catch (e) {
Expand All @@ -49,7 +49,7 @@ ${red("Je")}${green("C")}${gray("a")}${green("ptai")}${gray("n")}${red("-Luc")}$
throw new Error("assertNoDiff.chars didn't throw")
})

test("diffing against empty strings", function() {
test("diffing against empty strings", () => {
assertNoDiff.chars("", "")
})
})
20 changes: 10 additions & 10 deletions test/json.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { suite, test } from "node:test"
import stripAnsi from "strip-ansi"
import * as assertNoDiff from "../src/index"

suite("assertNoDiff.json", function() {
test("matching data", function() {
suite("assertNoDiff.json", () => {
test("matching data", () => {
const data = { firstName: "Jean-Luc", lastName: "Picard" }
assertNoDiff.json(data, data)
})

test("mismatching data", function() {
test("mismatching data", () => {
const obj1 = { firstName: "Jean-Luc", lastName: "Picard" }
const obj2 = { firstName: "Captain", lastName: "Picard" }
const expected = `mismatching objects:
Expand All @@ -19,28 +19,28 @@ ${gray("{\n")}${red(' "firstName": "Jean-Luc",\n')}${green(' "firstName": "Cap
gray(' "lastName": "Picard"\n}')
}`
assert.throws(
function() {
() => {
assertNoDiff.json(obj2, obj1)
},
new Error(expected)
)
})

test("no expected value", function() {
assert.throws(function() {
test("no expected value", () => {
assert.throws(() => {
// @ts-ignore
assertNoDiff.json("foo")
}, new Error("AssertNoDiff: expected value not provided"))
})

test("no actual value", function() {
assert.throws(function() {
test("no actual value", () => {
assert.throws(() => {
// @ts-ignore
assertNoDiff.json()
}, new Error("AssertNoDiff: actual value not provided"))
})

test("custom error message", function() {
test("custom error message", () => {
try {
assertNoDiff.json({ a: 1 }, { a: 2 }, "custom message")
} catch (e) {
Expand All @@ -51,7 +51,7 @@ ${gray("{\n")}${red(' "firstName": "Jean-Luc",\n')}${green(' "firstName": "Cap
throw new Error("assertNoDiff.json didn't throw")
})

test("diffing empty objects", function() {
test("diffing empty objects", () => {
assertNoDiff.json({}, {})
})
})
22 changes: 11 additions & 11 deletions test/trimmed-lines.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { suite, test } from "node:test"
import stripAnsi from "strip-ansi"
import * as assertNoDiff from "../src/index"

suite("assertNoDiff.trimmedLines", function() {
test("matching data", function() {
suite("assertNoDiff.trimmedLines", () => {
test("matching data", () => {
const data = "Jean-Luc Picard"
assertNoDiff.trimmedLines(data, data)
})

test("matching data with surrounding whitespace", function() {
test("matching data with surrounding whitespace", () => {
const obj1 = "foo"
const obj2 = " foo "
assertNoDiff.trimmedLines(
Expand All @@ -20,33 +20,33 @@ suite("assertNoDiff.trimmedLines", function() {
)
})

test("mismatching data", function() {
test("mismatching data", () => {
const obj1 = "Jean-Luc\nPicard"
const obj2 = "Captain\nPicard"

const expected = `mismatching lines:

${red("Jean-Luc\n")}${green("Captain\n")}${gray("Picard")}`
assert.throws(function() {
assert.throws(() => {
assertNoDiff.trimmedLines(obj2, obj1)
}, new Error(expected))
})

test("no expected value", function() {
assert.throws(function() {
test("no expected value", () => {
assert.throws(() => {
// @ts-ignore
assertNoDiff.trimmedLines("foo")
}, new Error("AssertNoDiff: expected value not provided"))
})

test("no actual value", function() {
assert.throws(function() {
test("no actual value", () => {
assert.throws(() => {
// @ts-ignore
assertNoDiff.trimmedLines()
}, new Error("AssertNoDiff: actual value not provided"))
})

test("custom error message", function() {
test("custom error message", () => {
try {
assertNoDiff.trimmedLines("one", "two", "custom message")
} catch (e) {
Expand All @@ -57,7 +57,7 @@ ${red("Jean-Luc\n")}${green("Captain\n")}${gray("Picard")}`
throw new Error("assertNoDiff.trimmedLines didn't throw")
})

test("diffing empty strings", function() {
test("diffing empty strings", () => {
assertNoDiff.trimmedLines("", "", "should allow diffing empty strings")
})
})
24 changes: 12 additions & 12 deletions test/words-with-space.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,53 @@ import { suite, test } from "node:test"
import stripAnsi from "strip-ansi"
import * as assertNoDiff from "../src/index"

suite("assertNoDiff.wordsWithSpace", function() {
test("matching data", function() {
suite("assertNoDiff.wordsWithSpace", () => {
test("matching data", () => {
const data = "Jean-Luc Picard"
assertNoDiff.wordsWithSpace(data, data)
})

test("mismatching data", function() {
test("mismatching data", () => {
const obj1 = "Jean-Luc Picard"
const obj2 = "Captain Picard"
const expected = `mismatching words:

${red("Jean-Luc")}${green("Captain")}${gray(" Picard")}`
assert.throws(function() {
assert.throws(() => {
assertNoDiff.wordsWithSpace(obj2, obj1)
}, new Error(expected))
})

test("extra whitespace", function() {
test("extra whitespace", () => {
const obj1 = "foo bar"
const obj2 = " foo bar"
const expected = `mismatching words:

${green(" ")}${gray("foo bar")}`
assert.throws(
function() {
() => {
assertNoDiff.wordsWithSpace(obj2, obj1)
},
new Error(expected),
"should not tolerate surrounding whitespace"
)
})

test("no expected value", function() {
assert.throws(function() {
test("no expected value", () => {
assert.throws(() => {
// @ts-ignore
assertNoDiff.wordsWithSpace("foo")
}, new Error("AssertNoDiff: expected value not provided"))
})

test("no actual value", function() {
assert.throws(function() {
test("no actual value", () => {
assert.throws(() => {
// @ts-ignore
assertNoDiff.wordsWithSpace()
}, new Error("AssertNoDiff: actual value not provided"))
})

test("custom error message", function() {
test("custom error message", () => {
try {
assertNoDiff.wordsWithSpace("one", "two", "custom message")
} catch (e) {
Expand All @@ -61,7 +61,7 @@ ${green(" ")}${gray("foo bar")}`
throw new Error("assertNoDiff.wordsWithSpace didn't throw")
})

test("empty strings", function() {
test("empty strings", () => {
assertNoDiff.wordsWithSpace("", "", "should allow diffing empty strings")
})
})