Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Commit

Permalink
fix: added class name to toString
Browse files Browse the repository at this point in the history
  • Loading branch information
jessekelly881 committed Dec 10, 2023
1 parent ad0c3bd commit e41e063
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4446,7 +4446,7 @@ const makeClass = <I, A>(
static [TypeId] = variance
toString() {
return pretty(this as any)
return `${this.constructor.name}(${pretty(this as any)})`
}
static pipe() {
Expand Down
10 changes: 6 additions & 4 deletions test/Schema/Class.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe("Schema/Class", () => {
const person = new Person({ id: 1, name: "John" })
const personAge = new PersonWithAge({ id: 1, name: "John", age: 30 })

expect(String(person)).toEqual(`{ "id": 1, "name": "John" }`)
expect(String(person)).toEqual(`Person({ "id": 1, "name": "John" })`)
expect(person instanceof Data.Class).toEqual(true)
expect(personAge instanceof Data.Class).toEqual(true)

Expand Down Expand Up @@ -211,7 +211,9 @@ describe("Schema/Class", () => {
it("TaggedClass", () => {
let person = new TaggedPersonWithAge({ id: 1, name: "John", age: 30 })

expect(String(person)).toEqual(`{ "_tag": "TaggedPerson", "id": 1, "age": 30, "name": "John" }`)
expect(String(person)).toEqual(
`TaggedPersonWithAge({ "_tag": "TaggedPerson", "id": 1, "age": 30, "name": "John" })`
)
expect(person._tag).toEqual("TaggedPerson")
expect(person.upperName).toEqual("JOHN")

Expand All @@ -237,7 +239,7 @@ describe("Schema/Class", () => {

let err = new MyError({ id: 1 })

expect(String(err)).toEqual(`{ "_tag": "MyError", "id": 1 }`)
expect(String(err)).toEqual(`MyError({ "_tag": "MyError", "id": 1 })`)
expect(err.stack).toContain("Class.test.ts:")
expect(err._tag).toEqual("MyError")
expect(err.id).toEqual(1)
Expand All @@ -258,7 +260,7 @@ describe("Schema/Class", () => {

let req = new MyRequest({ id: 1 })

expect(String(req)).toEqual(`{ "_tag": "MyRequest", "id": 1 }`)
expect(String(req)).toEqual(`MyRequest({ "_tag": "MyRequest", "id": 1 })`)
expect(req._tag).toEqual("MyRequest")
expect(req.id).toEqual(1)
expect(Request.isRequest(req)).toEqual(true)
Expand Down

0 comments on commit e41e063

Please sign in to comment.