I have a field where I want the value to either be optional OR have the field have a minimum length of 4. I’ve tried the following: This passes if I used a value like: “good”, but if I’ve got an empty value then it fails. How do I correctly implement a constraint using zod schemas to make an optional
Tag: schema
How to test mongoose pre hook ‘save’ and bcryptjs
I trying to create unit tests for mongoose model. I do not think how to test bcryptjs.hash in my schema. This is my User Schema: This is my test: But I have error is: TypeError: Attempted to wrap undefined property hash as function Answer You could mock the bcrypt doing that and your test could use