Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rush/mocha-finalize-each

Finalize each test in a mocha test suite and conditionally fail. This is a better afterEach.
https://github.com/rush/mocha-finalize-each

Last synced: 18 days ago
JSON representation

Finalize each test in a mocha test suite and conditionally fail. This is a better afterEach.

Awesome Lists containing this project

README

        

# mocha-finalize-each
Finalize each test in a mocha test suite and conditionally fail. This is a better afterEach. Stock `afterEach` halts the whole suite https://github.com/mochajs/mocha/issues/1635 in case of any `afterEach` failure

## Example

Below supports all types of tests: sync, async and promises. It unifies them to use promises so that `finalizeEach` can have a uniform interface.

```js
var finalizeEach = require('mocha-finalize-each');

describe('some tests', function() {
var sinonSandbox = sinon.sandbox.create();

// promise will be resolved after the test code resolves
finalizeEach(this, promise => {
// note: always return a promise here
// note2: if you .catch an error and don't re-throw it your tests will always pass
return promise.then(() => {
// will fail tests if sinon assertions are not satisfied
sinonSandbox.verifyAndRestore();
}).finally(() => {
// clean in all cases
sinonSandbox.restore();
});
});

it('some test', function() {
/* ... some code using sinonSandbox */
});
});
```