Some time ago I stumbled upon some crazy stuff… Specifically, I found out that SQLite has 787 times more tests than they have actual code! It’s no joke, it’s documented right on their website. While they have about 116 300 lines of source code, they have 91 577 300 lines of test code. That sounds completely insane. I bet you’ve …
The best resources to learn about JavaScript Promises
Promises can be both a blessing and a curse. They were supposed to clean the “callback pyramid of doom”, but instead they can often end up confusing (and I wanted to call that “The callback Temple of Doom”. It doesn’t really make sense in this context, I just like Indiana Jones) While promises do help, they are a lot more …
Mongoose models and unit tests: The definitive guide
A korean translation of this article Mongoose is a great tool, as it helps you build Node apps which use MongoDB more easily. Instead of having to sprinkle the model-related logic all over the place, it’s easy to define the functionality as Mongoose models. Querying MongoDB for data also becomes quick and easy – and if you ever need some …
How to unit test ES6 code?
ES6 is here today. Several browsers have almost all ES6 features available, and even Microsoft Edge is getting there. Tools like Babel help cover the parts which browsers don’t have yet. If you want to start using ES6 for development, that’s easy: there’s a lot of detailed information available. But what about testing? How do you write unit tests for …
Sinon.js quick tip: How to stub/mock complex objects, such as DOM objects
Several of my readers have emailed me, asking about how to deal with more complex stubbing situations when using Sinon.js. In this article, we’ll look at how to stub objects which are deeply nested, and when functions have more complex return values and they interact with other objects. We’ll use DOM objects as a practical example, as they’re used quite …
What is a Humble Object and how does it help make your code testable?
Some of the most common testing-related questions I’m asked relate to testing real-world apps. There’s always a difficult part that’s hard to test. Most often, it’s been the database. Sometimes I’ve also been asked about HTTP-based APIs like RESTful APIs and such. Let’s imagine a typical situation where you have some code that uses a database. You’ve got some code …
Using Sinon.js to make unit testing real-life apps easy
One of the biggest stumbling blocks when writing unit tests is what to do when you have code that’s non-trivial. In real life projects, code often does all kinds of things that make testing hard. Ajax requests, timers, dates, accessing other browser features… or if you’re using Node.js, databases are always fun, and so is network or file access. All …
Improving our React workflow with ES6 and functional stateless components
Someone once asked on Twitter about the concrete, real-world benefits of ES6 (or ES2015, as it’s officially known, despite nobody calling it that). It seems the benefits would be a bit difficult to measure: ES6 mostly just adds convenience. How does a convenience-feature benefit us? If you think about it, convenience makes code easier to write. When we have more …
Using WebRTC and React to build a basic chat server
In this article, we’re going to look at how to use WebRTC to relay chat messages between browsers in a React application. Last time we learned how to store and handle data in a React app. If you’ve just looking to learn about React and WebRTC, you should be able to follow this without reading the previous entries in the …
React application data-flow: Where and how to store your data?
This is the third article in the series where we build a Slack-style chat app with React. Last time we set up NPM and Browserify for our project. With the tooling set up, we can focus on building our application’s features again. The first feature I want to add is of course having multiple chat participants. But our code is …