Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nazarhussain/mocha-test-options
Extend Mocha BDD to provide test options
https://github.com/nazarhussain/mocha-test-options
Last synced: 29 days ago
JSON representation
Extend Mocha BDD to provide test options
- Host: GitHub
- URL: https://github.com/nazarhussain/mocha-test-options
- Owner: nazarhussain
- Created: 2015-12-10T23:26:10.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-02T20:36:37.000Z (almost 9 years ago)
- Last Synced: 2025-01-03T07:12:04.407Z (about 1 month ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# mocha-test-options
> Extend BDD Interfaces for Mocha to provide test options
[![Build Status](https://travis-ci.org/nazarhussain/mocha-test-options.svg?branch=master)](https://travis-ci.org/nazarhussain/mocha-test-options)
[![Code Climate](https://codeclimate.com/github/nazarhussain/mocha-test-options/badges/gpa.svg)](https://codeclimate.com/github/nazarhussain/mocha-test-options)In normal scenario you can set some variables/propertiess in `beforeEach` using `this.attribute = 'something'` and later can used it inside test cases. But in a scenario if you need to set some option in test and want to access it in `before` or `beforeEach` then this package will help you out.
### Setup
Then simply run mocha with `--ui mocha-test-options`.
### Example
```js
beforeEach(function(){
console.log(this.currentTest.testOptions)
})describe('scenario 1', function(){
it('test 11', {t1: true}, function(){
// Do something
});
})describe('scenario 2', {sc1: true}, function() {
it('test 21', {t1: true}, function(){
// Do something
});it('test 22', {t2: true}, function(){
// Do something
});it('test 23', function(){
// Do something
})
});
```You will get following output of console.
```
scenario 1{t1: true}
✓ test 11scenario 2
{sc1: true, t1: true}
✓ test 21{sc1: true, t2: true}
✓ test 22{sc1: true}
✓ test 23```
### Notes
- `describe`, `it` will accept a third parameter which you can pass for any options including objects of having functions
- The third parameter is optional, if you don't pass it will follow standard behavior
- This also applies to `only` and `skip` as well