# co-mocha

> Enable support for generators in Mocha tests

Latest version **1.2.2** (published 2018-02-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install co-mocha
pnpm add co-mocha
yarn add co-mocha
bun add co-mocha
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2018-02-27 |
| First published | 2014-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 212 |
| Author | Blake Embrey |
| Maintainers | blakeembrey |
| Keywords | co, mocha, harmony, generators |

## Links

- npm: https://www.npmjs.com/package/co-mocha
- Repository: https://github.com/blakeembrey/co-mocha
- Issues: https://github.com/blakeembrey/co-mocha/issues
- npm.io page: https://npm.io/package/co-mocha

## Dependencies (2)

- [co](https://npm.io/package/co.md) ^4.0.0
- [is-generator](https://npm.io/package/is-generator.md) ^1.0.1

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.2.2 (latest) — 2018-02-27
- 1.2.1 — 2017-10-11
- 1.2.0 — 2017-01-25
- 1.1.3 — 2016-08-01
- 1.1.2 — 2015-06-16
- 1.1.1 — 2015-06-16
- 1.1.0 — 2014-11-17
- 1.0.3 — 2014-10-28
- 1.0.2 — 2014-10-22
- 1.0.1 — 2014-09-01
- 1.0.0 — 2014-08-17
- 0.0.4 — 2014-05-05
- 0.0.3 — 2014-05-05
- 0.0.2 — 2014-03-03
- 0.0.1 — 2014-02-05

## README

# Co Mocha

[![NPM version][npm-image]][npm-url]
[![NPM downloads][downloads-image]][downloads-url]
[![Build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![Greenkeeper badge](https://badges.greenkeeper.io/blakeembrey/co-mocha.svg)](https://greenkeeper.io/)

Enable support for generators in Mocha tests using [co](https://github.com/visionmedia/co).

Use the `--harmony-generators` flag when running node 0.11.x to access generator functions, or transpile your tests using [traceur](https://github.com/google/traceur-compiler) or [regenerator](https://github.com/facebook/regenerator).

## Installation

```
npm install co-mocha --save-dev
```

## Usage

Just require the module in your tests and start writing generators in your tests.

```js
it('should do something', function * () {
  yield users.load(123)
})
```

### Node

Install the module using `npm install co-mocha --save-dev`. Now just require the module to automatically monkey patch any available `mocha` instances. With `mocha`, you have multiple ways of requiring the module - add `--require co-mocha` to your `mocha.opts` or add `require('co-mocha')` inside your main test file.

If you need to monkey patch a different mocha instance you can use the library directly:

```js
var mocha = require('mocha')
var coMocha = require('co-mocha')

coMocha(mocha)
```

### `<script>` Tag

```html
<script src="co-mocha.js"></script>
```

Including the browserified script will automatically patch `window.Mocha`. Just make sure you include it after `mocha.js`. If that is not possible the library exposes `window.coMocha`, which can be used (`window.coMocha(window.Mocha)`).

### AMD

Same details as the script, but using AMD requires instead.

## How It Works

The module monkey patches the `Runnable.prototype.run` method of `mocha` to enable generators. In contrast to other npm packages, `co-mocha` extends `mocha` at runtime - allowing you to use any compatible mocha version.

## License

MIT

[npm-image]: https://img.shields.io/npm/v/co-mocha.svg?style=flat
[npm-url]: https://npmjs.org/package/co-mocha
[downloads-image]: https://img.shields.io/npm/dm/co-mocha.svg?style=flat
[downloads-url]: https://npmjs.org/package/co-mocha
[travis-image]: https://img.shields.io/travis/blakeembrey/co-mocha.svg?style=flat
[travis-url]: https://travis-ci.org/blakeembrey/co-mocha
[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/co-mocha.svg?style=flat
[coveralls-url]: https://coveralls.io/r/blakeembrey/co-mocha?branch=master

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