Jest integration nested values #24102
Unanswered
alexnsorensen
asked this question in
Q&A
Replies: 1 comment
-
Hi @alexnsorensen 👋 Thank you for raising this question. Can you use prismaMock.person.findUniqueOrThrow.mockReturnValue({
posts: jest.fn().mockResolvedValue(posts),
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Question
I'm using Jest and jest-mock-extended to do unit testing on some more complex functions in my code. However I ran into an issue where I need to get nested data or something from prisma. and I can't see anything on Prisma's official website about this and couldn't see anything, I also had a read through this article
For example:
When I just run this code:
Jest works great and gets the mocked data, but when I add the .posts() I get an error saying TypeError: person.posts is not a function.
I do my mocked person data like so:
I understand why this error occurs, but I can't work out the syntax to get the mocked posts in there as everything I try throws a TS error.
Things I tried (assume data between the []):
How to reproduce (optional)
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
No response
Beta Was this translation helpful? Give feedback.
All reactions