#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 ...
#node #ava #Testing #javascriptJavaScript Object.defineProperty for a function: create mock object instances in Jest or AVAThis post goes through how to use Object.defineProperty to mock how constructors create methods, ie. non-enumerable properties that are functions. The gist of Object.defineProperty use with a function value boils down to: const obj = {} Object.defineProperty(obj, 'yes', { ...
#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 ...
#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 ...
#Testing #javascript #ProductivityAVA, low-config testing for JavaScriptA 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 from using global state and runs faster ...