# mocha-exports-ui

> extended built-in exports interface for Mocha

Latest version **0.0.3** (published 2016-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install mocha-exports-ui
pnpm add mocha-exports-ui
yarn add mocha-exports-ui
bun add mocha-exports-ui
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-03-21 |
| First published | 2016-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexander Petrovich |
| Maintainers | chopachom |
| Keywords | mocha, ui, interface, exports, testing, bdd |

## Links

- npm: https://www.npmjs.com/package/mocha-exports-ui
- Repository: https://github.com/chopachom/mocha-exports-ui
- Homepage: https://github.com/chopachom/mocha-exports-ui#readme
- Issues: https://github.com/chopachom/mocha-exports-ui/issues
- npm.io page: https://npm.io/package/mocha-exports-ui

## Dependencies (2)

- [mocha](https://npm.io/package/mocha.md) ^2.4.5
- [escape-string-regexp](https://npm.io/package/escape-string-regexp.md) ^1.0.4

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2016-03-21
- 0.0.2 — 2016-03-21
- 0.0.1 — 2016-03-20

## README

mocha-exports-ui
=====================

This projects lets you write your Mocha tests in the same way as original exports UI but it adds pending and exclusive tests plus shortcuts like `let` and `const` for assigning variables to the context.

Compare BDD interface and mocha-exports-ui interface:

```javascript
// mocha-exports-ui interface:
module.exports = {
  'User': {
    // will add variables to the context but only once (similar to `beforeAll`)
    const: {
      db: function(done){
        connect('some://connection/string', done);
      },
      User: function(){
        return this.db.model('User', UserSchema);
      }
    },
    // same as `const` but runs before each test like `beforeEach`
    let: {
      user: function(cb){
        new this.User({name: 'joe', password: 'qwerty', email: 'joe@gmail.com'}).save(done);
      }
    },
    // a test suite is just an object that can contain other test suites and tests
    '.signup': {
      // a test
      'returns an error if email exists': function(done){
        new this.User({name: 'another_joe', password: 'qwerty', email: 'joe@gmail.com'}).save(function(err){
          expect(err.message).to.contain('email exists');
          done(err);  
        });
      }
    },
    '#save': {
      // adding minus sign will skip the test, this is the same as calling `it.skip`
      '- it hashes password': function(){},
      'omits real password': function(){},
      // exclamation point makes a test or a suite exclusive, it is equivalent to  `it.only` or `describe.only`
      '! returns an error if email is changed to existing one': function(){}
    }
  }
}

// the same using regular BDD interface
describe('User', function(){
  before(function(done){
    const _this = this;
    connect('some://connection/string', function(err, db){
      if(err) return done(err);
      _this.db = db;
      _this.user = db.model('User', UserSchema);
    });  
  });  

  beforeEach(function(done){
    const _this = this;
    new this.User({name: 'joe', password: 'qwerty', email: 'joe@gmail.com'}).save(function(err, user){
      if(err) return done(err);
      _this.user = user;
      done(err);  
    });
  })
  describe.only('.signup', function(){
    it('returns an error if email exists', function(done){
      new this.User({name: 'another_joe', password: 'qwerty', email: 'joe@gmail.com'}).save(function(err){
        expect(err.message).to.contain('email exists');
        done(err);  
      });
    });
  });
  describe('#save', function(){
    it.skip('hashes password', function(){/* some code*/});
    it('doesn\'t save real password',function(){});
    it.only('returns an error if email changed to existing',function(){})
  });
})
```

See the `test/index.js` file in this repo for an example

#Usage

- Install the package: `npm install --save-dev mocha-exports-ui`
- Then just provide the UI name and mocha will automatically require `mocha-exports-ui`:
`mocha --ui mocha-exports-ui test/index.test.js `

###TODO: 
  - should add `let` and `const` to the error output, for instance instead of `"before each" hook for "adds variables to the context"` it should say `"let" hook for "adds variables to the context"`

---
_Source: https://npm.io/package/mocha-exports-ui · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
