I'm currently working on building a new Node.js application from the ground up at work. This is the first time I've done this for anything other than a personal side project, and I'd really like to do it right.
In pursuit of that goal, I want to introduce unit and integration tests early on in the process, but I don't have much (read: any) experience with unit tests in Node, so I'm not sure what all is out there. I've used Jasmine for AngularJS apps in the past, and while that was... rough, to say the least, I think that was more Angular's fault than Jasmine's, and I liked working with Jasmine overall. I've also heard good things about Mocha, though I've never done more than a couple toy examples myself. And I guess there's this thing called Jest that has popped up recently as well?
Are these frameworks still applicable in the server-side world? Are there newer, better frameworks I should be aware of?
How about for testing database interactions? I'd like to set up a harness that will run our migration scripts to build a little SQLite database on the fly for testing, something like that; is that the best approach?
I'm relatively new to this kind of testing, and I know we have some very experienced DEVs here, so any advice would be very welcome!
I'd also be happy to read any other articles that have been written on related subjects, so feel free to drop links!
Thanks in advance! 🙏😁
Top comments (2)
As far as test runners go, I think mocha and jest go neck and neck and are quite equal - although jest is easier to set up.
I really like Chai's chainable assertions, as they allow you to make complex assertions with ease, compared to jest's non-chainable ones.
The strongest point of jest is the jack-of-all-trades approach, when you don't need any other library for your tests.
Jest is just fantastic.
For mocking,stubbing etc Sinon is a good choice.