0.0.4 • Published 8 years ago

test-inject v0.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

test-inject

Build Status

Automatic dependency injection for test cases.

Installing

test-inject is available as an npm package.

Usage

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:

npm install

Run tests with:

npm test
0.0.4

8 years ago

0.0.3

8 years ago

0.0.1

8 years ago