Something that’s not talked very often when it comes to writing unit tests is how should you structure your test code? I’m not talking about “well, just put your code into a file in test/SomeTest.js”, but rather, how should the test code itself within your test case be structured? While it may feel inconsequential – afterall, it’s just a test, …
JavaScript Testing Tool Showdown: Sinon.js vs testdouble.js
When unit testing real-world code, there are many situations that make tests hard to write. How do you check if a function was called? How do you test an Ajax call? Or code using setTimeout? That’s when you use test doubles — replacement code that makes hard to test things easy to test. For many years, Sinon.js has been the …
230 Curated Resources and Tools for Building Apps with React.js
This post will curate the best resources, tools, libraries, and articles that will help you learn to build production applications with React.js. This 6000 word post will take you from getting started with React, through UI design, routing, testing, deployment, and continuous integration. There are many sections and you should feel free to jump to the resources you need.
Simplify your JavaScript code with normalizer functions
Everyone loves a good if-else tower! What could be simpler than nesting a few conditionals? if(stuff) { if(more stuff) { haha(); } else { cool(); } }if(stuff) { if(more stuff) { haha(); } else { cool(); } } Ok – that isn’t the most amazing thing in the world. In a simple example like this, it isn’t too bad. But …
Best practices for JavaScript function parameters
From time to time, people ask things like “should I use objects to pass function arguments”. I’m sure you recognize the pattern, as it’s common with many libraries: $.post({ a: ‘lot’, of: ‘properties’, live: ‘in’, here: ‘yep’ })$.post({ a: ‘lot’, of: ‘properties’, live: ‘in’, here: ‘yep’ }) But I would say this is not actually such a good idea. Let’s …
5 step method to make test-driven development and unit testing easy
What’s the hardest thing in test-driven development or unit testing in general? Writing tests! The syntax or the tools aren’t the problem – you can learn those enough to get started in 15 minutes. The problem is how to take some vague idea in your head about what you want to do, and turn it into something that verifies some …
What is property based testing (and how to do it in JavaScript)?
Ever wonder… what if you didn’t have to write specific tests with hardcoded test data? Or have you ever written a function which can take many different values as input? How can you test something like that easily with different values? These are the kinds of important questions in life that keep me up at night! (ok maybe not) But …
Staircase code – how short functions are not always the best solution
Have you ever seen code which at first look seems good.. but then as you try to figure it out (maybe to fix a bug), it just feels… wrong? For some reason the code just feels really difficult to follow – for no obvious reason! In this post, I’m going to explain one such occurrence that I ran into in …
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 …