#JavaScript #Sequelize #testing #Node

Mocking/stubbing ES6 classes in tests with examples of Sequelize model unit tests

This post goes through some patterns that can be used to unit test ES6 classes. The examples will use Jest module auto-mocking but should be portable to other module mocking libraries (eg. Proxyquire) with some modifications. In “Using ES6 classes for Sequelize 4 models” we explored how to define Sequelize models using ES6 classes. One of the benefits of such an approach is that it allows easy unit testing, it allows you to instantiate the model without the baggage of all of Sequelize (and/or a database). ...

  • Hugo Di Francesco
    Author
2 min read
#Testing #JavaScript #ES6

When to use Jest snapshot tests: comprehensive use-cases and examples 📸

There’s some nice use-cases for snapshot tests outside of the well-travelled React/Vue UI component ones. In other words, although React and Vue testing with snapshots is pretty well documented, that’s not the only place they’re useful. As a rule of thumb, you could replace a lot of unit tests that assert on with specific data with snapshot tests. We have the following pros for snapshot tests: - the match data is stored in a separate file so it’s harder to lose track of things, eg. ...

  • Hugo Di Francesco
    Author
6 min read
#JavaScript #Node #Testing

Testing an Express app with SuperTest, moxios and Jest

Testing is a crucial part of the software development process. It helps to catch bugs, avoid regressions and to document the behaviour of a piece of software. Express is one of the most widespread libraries for building backend applications in JavaScript. What follows is a summary of how to set up an efficient unit testing strategy for such an application as well as a couple of situations you may be faced with when attempting to test. ...

  • Hugo Di Francesco
    Author
6 min read
#VueJS #testing #JavaScript

From AngularJS to Vue.js, CommonJS and Jest

The trials and tribulations of kicking off an AngularJS -> Vue.js migration AngularJS was pretty groundbreaking. It’s still impressive to this day, packed with a router, an HTTP client, a dependency injection system and a bunch of other things I haven’t necessarily had the pleasure of dealing with. It also wraps most browser APIs as injectable services, that’s pretty cool. The downside is that it’s complicated: services, filters, injectors, directives, controllers, apps, components. ...

  • Hugo Di Francesco
    Author
7 min read
#Testing #JavaScript #Productivity

AVA, low-config testing for JavaScript

A JavaScript testing library for 2017 AVA is a Futuristic JavaScript test runner. Some of its best features are: it works out of the box, no need to specify a blob for test files or add Babel hooks it’s runs tests in parallel, this stops you from using global state and runs faster the tests are async by default I quite like AVA since I can just drop it in and reap benefits without too much hassle. ...

  • Hugo Di Francesco
    Author
4 min read