Node.js development can be a lot of fun. Unit testing can be fun too. Unit testing Node can be very much not fun. Unit testing Nodejs modules often feels like trying to build a neutered integration test with mocks, nocks, and intercepts. Since Node is a web server whose functionality revolves around responding to http requests, the most natural testing method would be to trip those URLs and check the response. However, that ends up being more of a test of the middleware, and doesn't allow for testing the function directly. If you want to ignore the http calls, the most rational way to test the functions inside the module would be to export them. Once exported the tests can easily be run against the exported functions. The problem with exposing all the functions via export means functionality that should be private is no longer private.
Showing posts with label Debugging. Show all posts
Showing posts with label Debugging. Show all posts
10/21/2013
11/27/2012
Solve the Problem, Not the Behavior
In my past life of consultancy I became very used to working on other people's code. One of the most important lessons I learned was to "find the problem first". Errors are a behavior you witness. Debugging is fixing those errors. Most developers would consider those reasonable statements. There is an underhanded trick here though. Some developers might make the mistake of a direct connection between the two, but there isn't. The error you witness may not be the error you need to fix.
Subscribe to:
Posts (Atom)