An open API service indexing awesome lists of open source software.

https://github.com/sboudrias/generator-jest

Add jest support to any projects
https://github.com/sboudrias/generator-jest

Last synced: 3 months ago
JSON representation

Add jest support to any projects

Awesome Lists containing this project

README

          

# generator-jest [![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][codecov-image]][codecov-url]

> Add jest support to any projects

## Installation

First, install [Yeoman](http://yeoman.io) and generator-jest using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo generator-jest
```

Then generate your new project:

```bash
yo jest
```

Once done, you can run tests using `npm test`.

To generate tests for your components, you can then run:

```bash
yo jest:test path/to/file-to-test.js

# (optional) You can specifically define your component name
yo jest:test path/to/file-to-test.js --componentName=useThisName
```

## Include generator-jest in your own generator

`generator-jest` is built to create as minimum overhead as possible when including in your own generators.

First, install `generator-jest` as a dependency of your own generator.

```bash
npm install --save generator-jest
```

Then call it from your generator.

```js
this.composeWith(require.resolve('generator-jest/generators/app'), {
testEnvironment: 'jsdom', // (optional) pass one of jsdom or node
coveralls: true // (optional) send coverage reports to coveralls
});

this.composeWith(require.resolve('generator-jest/generators/test'), {
filepath: 'components/Sidebar.jsx'
componentName: 'SideBar' // (optional) define the component name
});
```

Note: Tests generated by `jest:test` will fail by default. Users should implement relevant tests.

## License

MIT © [Simon Boudrias](https://github.com/SBoudrias)

[npm-image]: https://badge.fury.io/js/generator-jest.svg
[npm-url]: https://npmjs.org/package/generator-jest
[daviddm-image]: https://david-dm.org/SBoudrias/generator-jest.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/SBoudrias/generator-jest
[codecov-image]: https://codecov.io/gh/SBoudrias/generator-jest/branch/master/graph/badge.svg
[codecov-url]: https://codecov.io/gh/SBoudrias/generator-jest