user3618284
user3618284

Reputation: 37

How can I make unit test on a nodejs app?

I want to make some unit tests on my nodejs app in order to test the insertion of a user on a database or the read of a user from the database. I'm using Objection.js such an ORM and I searched through the net how to do these Test, thus I found Sinon to mock a database or a model.Concerning this issue I found also this question Mocking database in node.js?. For example if I have a table Users contains 10 users, is there any solutions to get all the rows of such table for example of fetch if a user exists in the table? I don't really understand the concept of mocking and if it is the suitable solution to make such tests?

Upvotes: 0

Views: 122

Answers (1)

Osama Bari
Osama Bari

Reputation: 598

There are lots of libs for unit testing of NodeJS such as Moca, Chai, Jasmine.

here is some tutorial link:

https://www.codementor.io/davidtang/unit-testing-and-tdd-in-node-js-part-1-8t714s877

https://blog.risingstack.com/node-hero-node-js-unit-testing-tutorial/

Upvotes: 2

Related Questions