-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More robust undefined value checking for format()
- Loading branch information
Showing
5 changed files
with
60 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const ValueError = require("../../lib/errors/ValueError"); | ||
|
||
// Tests. | ||
describe("ValueError()", () => { | ||
test("Return correct error with default message", () => { | ||
expect(new ValueError()).toHaveProperty("name", "ValueError"); | ||
expect(new ValueError()).toHaveProperty("message", "Invalid value"); | ||
expect(new ValueError()).toHaveProperty("prefix", ""); | ||
expect(new ValueError()).toHaveProperty("reason", "Invalid value"); | ||
expect(new ValueError()).not.toHaveProperty("value"); | ||
}); | ||
test("Return correct error with message only", () => { | ||
expect(new ValueError("Message")).toHaveProperty("name", "ValueError"); | ||
expect(new ValueError("Message")).toHaveProperty("message", "Message"); | ||
expect(new ValueError("Message")).toHaveProperty("prefix", ""); | ||
expect(new ValueError("Message")).toHaveProperty("reason", "Message"); | ||
expect(new ValueError("Message")).not.toHaveProperty("value"); | ||
}); | ||
test("Return correct error with message and value", () => { | ||
expect(new ValueError("Message", 123)).toHaveProperty("name", "ValueError"); | ||
expect(new ValueError("Message", 123)).toHaveProperty("message", "Message (received 123)"); | ||
expect(new ValueError("Message", 123)).toHaveProperty("prefix", ""); | ||
expect(new ValueError("Message", 123)).toHaveProperty("reason", "Message"); | ||
expect(new ValueError("Message", 123)).toHaveProperty("value", 123); | ||
}); | ||
test("Return correct error with message, value, and prefix", () => { | ||
expect(new ValueError("Message", 123, "Prefix")).toHaveProperty("name", "ValueError"); | ||
expect(new ValueError("Message", 123, "Prefix")).toHaveProperty("message", "Prefix: Message (received 123)"); | ||
expect(new ValueError("Message", 123, "Prefix")).toHaveProperty("prefix", "Prefix"); | ||
expect(new ValueError("Message", 123, "Prefix")).toHaveProperty("reason", "Message"); | ||
expect(new ValueError("Message", 123, "Prefix")).toHaveProperty("value", 123); | ||
}); | ||
}); |