Pass router context to child components when testing in Enzyme/Jest

Adding a Link to a React component was easy as it sounds, except that it broke half of the unit tests. I started getting “Invariant Violation: You should not use <Link> outside a <Router>” which explains itself, but sorting it out took quite some time. In my component I’ve been using withRouter, but the tests are done on a disconnected component without the router and the Link component requires the router context. While mostly understood the issue, when trying most of the suggestions, I kept getting the above error, or “Warning: Failed context type: The context router is marked as required in Component, but its value is undefined“. So let’s see how to pass the router context to child components when testing in Enzyme/Jest.



Tagged with
Comment

Testing NodeJS – Express with Mongoose

In the previous post I started testing the Node/Express application which I created before. So far we only added some tests to the Mongoose models and now I want to make sure, that the REST API keeps doing what I want it to do. In addition to using Mocha and Chai, which we looked at previously, now I will take a look at Supertest to make calls to Express and Sinon to stub calls.



Tagged with
Comment

Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’

When running ng test I got "Can't bind to 'ngModel' since it isn't a known property of 'input'", even though if I run the code with ng serve, there is no issue. This post is a hint to include core module dependencies, when setting up the TestBed in Angular 2.



Tagged with
Comment

Start testing NodeJS – Mongoose

Before continuing to create the REST API which I started and extended in previous posts, let’s take a look at testing. I should’ve started with this I guess, but maybe it’s not too late yet. In the previous posts at the end we tested the results manually either using Postman or cURL. These tests were of course nowhere near complete and if we broke something it remained hidden for too long. In this post I will create some tests for this NodeJS application, first focusing on the MongooseJS models, then in a next post taking a look at testing opportunities of the ExpressJS routes.



Tagged with
Comment