-
Notifications
You must be signed in to change notification settings - Fork 153
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
Sample unit test for model #141
Comments
When I tried to setup a globalSetup (instead of BeforeAll). It caused an issue like below. It seems mongoose don't store the models in globalSetup
|
Hi @1change, sorry for the late response, life has been busy lately. Glad you got a working example. For your 'globalSetup', are you trying to run an external setup script (like the
Also, for the code you posted, since you are using |
Hi @JKHeadley, thx for taking the time. Yes beforeAll won't call server every time but in every testspec, so having a globalSetup would help. |
I went through some trial & errors, too, and I think I came to a decent solution.
this can be useful too. |
@sanzoghenzo very nice! Yes getting things in the right order can be a bit tricky. Thanks for sharing your solution! As a side note, if you find spinning up a MongoDB instance too slow or cumbersome, you can using mongodb-memory-server. See this comment. |
Is your feature request related to a problem? Please describe.
I'm new to Hapi & mongoose and trying to setup unit test for some model I define with Jest, but having found no references on google how to do it properly, so running into some sort of trial and error to make it work.
Describe the solution you'd like
One sample unit test where you could run CRUD or call method in a model
Describe alternatives you've considered
Additional context
Above is my trial and it works but could have been better, I guess having a setup.js and not calling generateModels and server.start every time.
The text was updated successfully, but these errors were encountered: