Replies: 3 comments 5 replies
-
Percolating on this a bit more - yes I am doing something weird. So this isn't going to be a standard issue to have. For a bit of context, we have our own in-house library for factories. Pretty simular to Laravel's API (https://laravel.com/docs/10.x/eloquent-factories) Too many tests use these for us to initially move over to Joist's factories, so I've been reworking our in-house factories to build Joist entities. I clearly haven't finished that work :D That's why we're experiencing ValidationErrors at flush - because of a lack of type-safety at em.create (within factories) - whereas in normal usage, ValidationErrors will be prevented as a TS type issue. Happy to close. |
Beta Was this translation helpful? Give feedback.
-
Yeah, we've ran into this as well, and are currently using the old
For the not-type-safe It is probably worth keeping an issue/discussion open for this, b/c it is annoying, and hopefully we can find a more kosher way around it than pinning to jest-jasmine2. Probably worth an FAQ/note in the docs as well... |
Beta Was this translation helpful? Give feedback.
-
This landed in v1.89.2 |
Beta Was this translation helpful? Give feedback.
-
Creating this as a discussion as it's perhaps debatable if Joist should go out of its way to support this.
Essentially, Jest w/ workers posts the errors of test back to the root process using JSON.stringify.
ValidationErrors
holdsentities
which might contain circular references which JSON.stringify throws up on.Unfortunetly a basic
toJSON
method on ValidationErrors doesn't fix this, a la:It just wasn't getting picked up... but as a property it does work; so I suspect Jest is spreading the object prior to stringifcation.
I'm happy to PR this if it's something you're happy to have included (the property bit is annoying as this is probably a Jest only thing), but from a dx point of view I'm suprised others haven't hit this (perhaps it's something weird I'm doing) otherwise we have a workaround in extending EntityManager in our tests and catching and rethrowing validation errors without
entities
.Beta Was this translation helpful? Give feedback.
All reactions