Node Testing Essentials (A node developer's guide to testing)
CRANK

Recently, I started to write complex tests for node and I realized that I need to use more than one library to effectively test node projects. However, I couldn't find a comprehensive guide for how to use those libraries together to create a robust test so I decided to share my experience to save you some time.Note that this is not a step-by-step tutorial but simply a guide to the tools and how to use them together. ToolboxFirst of all, allow me to introduce the tools I use for testing.Mocha: Framework for testing JS. Basically the skeleton of the tests.Chai: Assertions library with many useful plugins.Nock: A library that allows you to override the response of exact http requests with your own response.Sinon: Library for stubbing and mocking functions and objects.Now let's get into more details about each tool. 1. MochaMocha is the main testing framework. We use it to:Define test scenarios. (Using describe)Define test cases in each scenario. (Using it)Run tests using mocha command.So…

dev.to
Related Topics: