-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix: add toJSON to ValidationErrors #693
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, thanks!
constructor(errors: ValidationError[]); | ||
constructor(message: string); | ||
constructor(messageOrErrors: ValidationError[] | string) { | ||
super(typeof messageOrErrors === "string" ? messageOrErrors : errorMessage(messageOrErrors)); | ||
this.errors = typeof messageOrErrors === "string" ? [] : messageOrErrors; | ||
// Jest clones without prototype, so explictly setting this as a property rather than a class method | ||
// https://github.com/jestjs/jest/issues/11958 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I wonder if this is what we missed, i.e. I probably tried defining toJSON as class method. Great comment!
packages/orm/src/rules.ts
Outdated
constructor(errors: ValidationError[]); | ||
constructor(message: string); | ||
constructor(messageOrErrors: ValidationError[] | string) { | ||
super(typeof messageOrErrors === "string" ? messageOrErrors : errorMessage(messageOrErrors)); | ||
this.errors = typeof messageOrErrors === "string" ? [] : messageOrErrors; | ||
// Jest clones without prototype, so explictly setting this as a property rather than a class method | ||
// https://github.com/jestjs/jest/issues/11958 | ||
this.toJSON = () => `<ValidationErrors> ${this.message}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind making this ValidationErrors: ${this.message}
? I just realized/remembered that EntityManager.toJSON
s also uses this <...>
syntax but not sure why we did that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing! I was also debating returning { message }
which would be the default response if we weren't overriding this (sans .entities obviously)
## [1.89.2](v1.89.1...v1.89.2) (2023-06-16) ### Bug Fixes * add toJSON to ValidationErrors ([#693](#693)) ([b3c49bd](b3c49bd))
🎉 This PR is included in version 1.89.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Following on from #692.
This (from my testing, Jest 29.5.0 w/ Circus) should stop issues around circular references by introducing toJSON as a property of ValidationErrors which survives the clone.
I've added in a test to attempt to represent this issue, wasn't sure the best place for it - happy to move/change.