Hey all, I’ve been using the Nexus test setup exam...
# graphql-nexus
w
Hey all, I’ve been using the Nexus test setup examples to TDD a new app, and I ran into an issue. I managed to track down the problem and solve it, but I’d appreciate help or ideas for how to make the solution more elegant. Basically, the setup provided here will only work for the first test in a suite. All subsequent tests fail. It took me days to track down why, but it’s basically because this line
Copy code
serverInstance = await server.listen({ port });
invokes a server implementation that uses a generic
PrismaClient
instance from your main app server. Obviously, that means that if you import or define your server or database differently in your project setup, you may experience different symptoms. My solution is basically to create a server generator function that takes an optional
PrismaClient
instance as an argument and use that as the database. Then in the test setup you can pass the newly created
PrismaClient
to the server. Without that on the server definition, every test will attempt to refer to the client created in the first test block, even after it’s been torn down.
r
Hey @Will Fischer 👋 Although this is different from what you’re looking for, maybe adding a function here with an optional PrismaClient parameter would work in this case.