mocha-ur2ue

Mocha root hook plugin to convert unhandled rejection events to unhandled exceptions so that they will cause test failures.


Keywords
mocha, mocha-plugin, promise
License
MIT
Install
npm install mocha-ur2ue@1.0.0

Documentation

mocha-ur2ue

Build Status Dependency Status Supported Node Version Version on NPM

A Mocha root hook plugin to convert unhandledrejection events to unhandled exceptions so that they will cause test failures. This works around a long-standing issue (mochajs/mocha#1926 and mochajs/mocha#2640) that unhandled rejections do not cause test failure in Mocha.

Introductory Example

npm install --save-dev mocha mocha-ur2ue
mocha --require mocha-ur2ue --recursive tests

Node.js Alternatives

On Node.js v10.17 and later, the behavior of this module can be accomplished by invoking Node.js with --unhandled-rejections=throw:

node --unhandled-rejections=throw node_modules/mocha/bin/mocha --recursive test

or by setting NODE_OPTIONS=--unhandled-rejections=throw in the environment:

NODE_OPTIONS=--unhandled-rejections=throw mocha --recursive test

--unhandled-rejections=throw became the default in Node.js v15, making this module unnecessary with v15 and later.

Installation

This package can be installed using npm, either globally or locally, by running:

npm install mocha-ur2ue

Contributing

Contributions are appreciated. Contributors agree to abide by the Contributor Covenant Code of Conduct. If this is your first time contributing to a Free and Open Source Software project, consider reading How to Contribute to Open Source in the Open Source Guides.

If the desired change is large, complex, backwards-incompatible, can have significantly differing implementations, or may not be in scope for this project, opening an issue before writing the code can avoid frustration and save a lot of time and effort.

License

This project is available under the terms of the MIT License. See the summary at TLDRLegal.