Fetching search results for ""
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...
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 runs tests in parallel, this stops you...
Jest .fn() and .spyOn() spy/stub/mock assertion reference
Where other JavaScript testing libraries would lean on a specific stub/spy library like Sinon - Standalone test spies, stubs and mocks for JavaScript. Works with any unit testing framework., Jest comes with stubs, mocks and spies out of the...
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...
What is Jest and why should I use it?
Jest is a delightful JavaScript Testing Framework with a focus on simplicity. jestjs.io Jest is a batteries-included framework. Due to its fully-featured nature and large surface area, we can compare it to test runners (Mocha), assertion...
Jest explicitly or arbitrarily force fail() a test
When testing code with Jest, it can sometimes be useful to fail a test arbitrarily. This post goes through a few scenarios where that might be useful and how to fail a Jest test explicitly/in a forced manner. It also presents more idiomatic...
A testing guide for Express with request and response mocking/stubbing using Jest or sinon
To test an Express handler, it’s useful to know how to successfully mock/stub the request and response objects. The following examples will be written both using Jest and sinon (running in AVA). The rationale for this is the following. Jest...
Jest Full and Partial Mock/Spy of CommonJS and ES6 Module Imports
JavaScript import/require module testing do’s and don’ts with Jest The example repository is available at github.com/HugoDF/mock-spy-module-import. This post goes through how to achieve different types of module mocking...
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...