Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for the
Ono.toJSON()
static method
- Loading branch information
1 parent
24ad3bc
commit 5dfeb49
Showing
3 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use strict"; | ||
|
||
const { Ono } = require("../../"); | ||
const { expect } = require("chai"); | ||
const { comparePOJO } = require("../utils"); | ||
|
||
describe("Ono.toJSON()", () => { | ||
|
||
it("should return all built-in error properties", () => { | ||
let err = new TypeError("Something went wrong"); | ||
|
||
expect(Ono.toJSON(err)).to.satisfy(comparePOJO({ | ||
name: "TypeError", | ||
message: "Something went wrong", | ||
stack: err.stack | ||
})); | ||
}); | ||
|
||
it("should return custom properties", () => { | ||
let err = new SyntaxError("Something went wrong"); | ||
err.foo = "bar"; | ||
err.biz = 5; | ||
|
||
expect(Ono.toJSON(err)).to.satisfy(comparePOJO({ | ||
name: "SyntaxError", | ||
message: "Something went wrong", | ||
stack: err.stack, | ||
foo: "bar", | ||
biz: 5 | ||
})); | ||
}); | ||
|
||
it("should return object properties", () => { | ||
let obj = { foo: "bar" }; | ||
let date = new Date(); | ||
let regex = /xyz/; | ||
|
||
let err = new Error("Something went wrong"); | ||
Object.assign(err, { obj, date, regex }); | ||
|
||
expect(Ono.toJSON(err)).to.satisfy(comparePOJO({ | ||
name: "Error", | ||
message: "Something went wrong", | ||
stack: err.stack, | ||
obj, | ||
date, | ||
regex, | ||
})); | ||
}); | ||
|
||
}); |
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