# babel-plugin-testable

> Babel plugin that exports private members for testing purposes

Latest version **1.0.0** (published 2018-09-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-testable
pnpm add babel-plugin-testable
yarn add babel-plugin-testable
bun add babel-plugin-testable
```

## 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.0.0 |
| Published | 2018-09-07 |
| First published | 2018-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 149.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jetclosing |
| Keywords | babel, babel-plugin, test, testing, mocha, jest, testable, export |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-testable
- Repository: https://github.com/JetClosing/babel-plugin-testable
- Homepage: https://github.com/JetClosing/babel-plugin-testable#readme
- Issues: https://github.com/JetClosing/babel-plugin-testable/issues
- npm.io page: https://npm.io/package/babel-plugin-testable

## 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

- 1.0.0 (latest) — 2018-09-07
- 0.1.0 — 2018-08-23

## README

# babel-plugin-testable

Babel plugin that exports private members for testing purposes

![npm downloads total](https://img.shields.io/npm/dt/babel-plugin-testable.svg) ![npm version](https://img.shields.io/npm/v/babel-plugin-testable.svg) ![npm license](https://img.shields.io/npm/l/babel-plugin-testable.svg)

## Installation

```sh
npm install babel-plugin-testable --save-dev
```
or
```sh
yarn add babel-plugin-testable --dev
```

### Enable Plugin

Add `babel-plugin-testable` to your `.babelrc`

```json
{
  "plugins": ["testable"]
}
```
or 
```json
{
  "env": {
    "test": {
      "plugins": [ "testable" ]
    }
  }
}
```

## Usage

In your source file, annotate the private members that should be exposed for testing with an `// @testable` comment. Example:

```javascript
// @testable
const MY_PRIVATE_CONSTANT = 'Some constant';

// @testable
let someTestableField = true;

// @testable - This is a testable class with additional comments
class TestableClass {
  // Class code
}
```

Then in your test file, you can import them like any other exported 
declaration.

```javascript
import { publicFunction, MY_PRIVATE_CONSTANT } from '../';

it('Test MY_PRIVATE_CONSTANT', () => {
  expect(MY_PRIVATE_CONSTANT).toBe('Some constant');
});
```

## Options

The plugin provides the following options to tweak the behavior of the plugin during code generation.

| Option | Values | Default | Description  |
| :--- | :--- | :--- | :--- |
| `testComment` | String | `testable` | The comment name to key off for exporting testable code |
| `testCommentRegex` | Regular Expression | `^\s*@##comment##\b` | The comment regular expression to search for testable code. `##comment##` is the placeholder used for the value of `testComment`. |

#### Options Example

A `.babelrc` configuration example which looks for `__TestExport__` anywhere in a comment.

```json
{
  "plugins": [
    [ 
      "testable", 
      {
        "testComment": "TestExport",
        "testCommentRegex": ".*__##comment##__.*"
      }
    ]
  ]
}
```

## Example Output Code

```javascript
// @testable
export const MY_PRIVATE_CONSTANT = 'Some constant';

// @testable
export let someTestableField = true;

// @testable - This is a testable class with additional comments
export class TestableClass {
  // Class code
}
```

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