#jest #node #javascript #testingJest Array/Object partial match with objectContaining and arrayContainingIt’s possible to do partial matches on Arrays and Objects in Jest using expect.objectContaining and expect.arrayContaining. expect has some powerful matcher methods to do things like the above partial matches. Using Jest at an advanced level means using tools like these to ...
#javascript #jest #node #testingJest explicitly or arbitrarily force fail() a testWhen 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 Jest patterns that could be used interc ...
#node #javascript #pythonHow to integrate Python/Ruby/PHP/shell script with Node.js using child_process.spawn or child_process.execThere are occasions when running a Python/Ruby/PHP shell script from Node.js is necessary. This post looks at best practices around leveraging child_process.spawn and child_process.exec to encapsulate this call in Node.js/JavaScript. The goal here is to have an interoperability l ...
#javascript #jest #node #es6 #testingJest Full and Partial Mock/Spy of CommonJS and ES6 Module ImportsJavaScript 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 scenarios with Jest. From simple Import interce ...
#jest #javascript #node #testingHow to run, ignore or skip Jest tests, suites and filesWhen debugging or writing units tests with Jest it can be useful to specify a single file or test to run or to exclude a specific failing test for the Jest run. This post goes how to skip and exclude a single test, a whole Jest test suite and a whole Jest test file using the CLI ...
#micro #node #javascript #SQLiteRecord analytics events with a Zeit "micro" + SQLite3 Node.js applicationmicro-analytics-events - A Node.js microservice to record analytics events to SQLite3 with Zeit’s “micro” In order to finally switch off Google Analytics, I need to replace my goal conversion tracking somehow. I’ve got pageview data using Simple Analytics ...
#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 #nodeDetect if the current file/module is the entrypoint or import/require-d in Node.jsHow does one identify whether a JavaScript file is being run directly (node file.js) or it’s being import/require-d (require('./file') in another JS file). In Python the pattern leverages the __main__ property in modules like so: if __name__ == '__main__': # do some ...
#javascript #node #metaYarn Workspaces: monorepo management without Lerna for applications and coding examplesHow to use Yarn Workspaces to manage applications/coding examples. Lerna isn’t required when you don’t need the git diffing and versioning facilites. What’s more Yarn Workspaces are a great lightweight tool to get up and running faster for simple Node.js monore ...
#node #lunrjs #hugo #meta #javascriptAdd Search to a Hugo site with Lunr.js and Node.jsHugo “The world’s fastest framework for building websites” is a great option for JAMStack (JavaScript, APIs, prebuild Markup) sites. Lunr.js is “A bit like Solr, but much smaller and not as bright”, it’s a pure JavaScript implementation of a Solr-lik ...