# test-inject

> Automatic dependency injection for test cases

Latest version **0.0.4** (published 2016-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install test-inject
pnpm add test-inject
yarn add test-inject
bun add test-inject
```

## 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.4 |
| Published | 2016-08-28 |
| First published | 2016-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Vinson Chuong |
| Maintainers | vinsonchuong |

## Links

- npm: https://www.npmjs.com/package/test-inject
- Repository: https://github.com/vinsonchuong/test-inject
- Issues: https://github.com/vinsonchuong/test-inject/issues
- npm.io page: https://npm.io/package/test-inject

## Dependencies (1)

- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.5

## Recent versions

- 0.0.4 (latest) — 2016-08-28
- 0.0.3 — 2016-08-24
- 0.0.1 — 2016-08-23

## README

# test-inject
[![Build Status](https://travis-ci.org/vinsonchuong/test-inject.svg?branch=master)](https://travis-ci.org/vinsonchuong/test-inject)

Automatic dependency injection for test cases.

## Installing
`test-inject` is available as an
[npm package](https://www.npmjs.com/package/test-inject).

## Usage
```js
import test from 'ava';
import register from 'test-inject';
import Directory from 'directory-helpers';

const inject = register({
  src: {
    setUp() {
      return new Directory('src');
    },
    async tearDown(src) {
      await src.remove();
    }
  },
  spec: {
    setUp() {
      new Directory('spec');
    },
    async tearDown(spec) {
      await spec.remove();
    }
  }
});

test('it works', inject((t, {src}) => {
  await src.write({'index.js', "console.log('Hello World!')"});
  test.is(await src.read('index.js'), "console.log('Hello World!')");
}))
```

`setUp` is called only for the requested dependencies, their return values
being injected into the test. Note that if `setUp` is `async` or returns a
`Promise`, the test will have to `await` its resolution.

## Development
### Getting Started
The application requires the following external dependencies:
* Node.js

The rest of the dependencies are handled through:
```bash
npm install
```

Run tests with:
```bash
npm test
```

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