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
- Host: GitHub
- URL: https://github.com/sboudrias/generator-jest
- Owner: SBoudrias
- License: mit
- Created: 2016-12-01T03:02:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-29T06:32:52.000Z (6 months ago)
- Last Synced: 2025-06-29T21:46:57.918Z (3 months ago)
- Language: JavaScript
- Size: 1.49 MB
- Stars: 19
- Watchers: 3
- Forks: 10
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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