Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/rush/mocha-finalize-each
- Owner: Rush
- License: mit
- Created: 2017-08-19T19:03:19.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-06-10T04:09:42.000Z (over 6 years ago)
- Last Synced: 2024-10-15T04:06:40.912Z (22 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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 */
});
});
```