#jest #javascript #node #testingHow to run Jest tests sequentiallyBy default Jest runs tests in parallel with a “a worker pool of child processes that run tests” (Jest CLI docs). As per the Jest documentation, running tests in sequence (serially), can be helpful for debugging purposes and for test run performance reasons. ...
#javascript #jest #testing #nodeJest ignore or exclude file/function/statement from test coverageIn computer science, test coverage is a measure used to describe the degree to which the source code of a program is executed when a particular test suite runs. Code coverage - Wikipedia Code coverage is usually used as a quality metric for software eg. “Our code has to have 80% ...
#javascript #node #jest #testing #MongoDBAvoiding recursion pitfalls: MongoDB nested query clause addition and removalA case-study on where recursion can be useful for enterprise Node.js applications and how to avoid its common pitfalls like RangeError: Maximum call stack size exceeded. The full repository for this post is on GitHub: github.com/HugoDF/mongo-query-clause-modification We’ll ...
#testing #jest #node #javascript #jestJest assert over single or specific argument/parameters with .toHaveBeenCalledWith and expect.anything()With Jest it’s possible to assert of single or specific arguments/parameters of a mock function call with .toHaveBeenCalled/.toBeCalled and expect.anything(). The full example repository is at github.com/HugoDF/jest-specific-argument-assert, more specifically lines 17-66 i ...
#Express #node #jest #Testing #javascriptA testing guide for Express with request and response mocking/stubbing using Jest or sinonTo 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 is a very popular “all-in-one” testing ...
#node #jest #testing #javascript #SequelizeMocking/stubbing ES6 classes in tests with examples of Sequelize model unit testsThis 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&rdq ...
#jest #Testing #javascriptWhen 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 c ...
#jest #javascript #node #ExpressTesting an Express app with SuperTest, moxios and JestTesting 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 summar ...
#vuejs #jest #testing #javascriptFrom AngularJS to Vue.js, CommonJS and JestThe 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 pl ...