# generator-rn-jest-gen

> RN + TypeScript + Jest Unit test cases generator

Latest version **1.0.2** (published 2022-09-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install generator-rn-jest-gen
pnpm add generator-rn-jest-gen
yarn add generator-rn-jest-gen
bun add generator-rn-jest-gen
```

## 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.2 |
| Published | 2022-09-30 |
| First published | 2022-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Suresh Konakanchi |
| Maintainers | sur950 |
| Keywords | yeoman-generator, rn test cases, jest, jest test cases, react native jest, test generator |

## Links

- npm: https://www.npmjs.com/package/generator-rn-jest-gen
- Repository: https://github.com/sur950/rn-jest-gen
- Homepage: https://github.com/sur950/rn-jest-gen#readme
- Issues: https://github.com/sur950/rn-jest-gen/issues
- npm.io page: https://npm.io/package/generator-rn-jest-gen

## 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.2 (latest) — 2022-09-30
- 1.0.1 — 2022-09-30

## README

# React-native jest test case generator

## What's that ?

This is a plugin which generates the Jest unit test cases by parsing typescript formatted react native components using [Yeoman](http://yeoman.io) generator.
The tests are linted with [prettier](https://github.com/prettier/prettier) and outputted to the current directory's ```__tests__``` folder.

## Why ?

Generating proper test cases for well-defined components can (and should) easily be offloaded in this library. This is a solution I use across projects to fasten my tests.

## Installation

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

```js
npm install -g yo
npm install generator-rn-jest-gen
```

## Commands

Suppose you have the following file structure

```js
- app/
  - screens/
    - Home.ts
    - Dashboard.ts
    - Drawer.ts
```

To Generate test file :

```js
yo rn-jest-gen:test
```

To Generate test file with debugger :

```js
DEBUG=generator-rn-jest-gen* yo rn-jest-gen:test
```

```bash
     _-----_     
    |       |    
    |--(o)--|    ╭──────────────────────────╮
   `---------´   │      Create RN tests     │
    ( _´U`_ )    ╰──────────────────────────╯
    /___A___\   /
     |  ~  |     
   __'.___.'__   
 ´   `  |° ´ Y ` 

? Give me the path to components please ! (./src/screens/)
```

When terminal prompts you with the above question, Kindly provide the path to your folder where you had UI Components or Simply navigate to the folder where you had only UI Components by doing ```cd``` and put ```./``` as path.

Then the generator will create a ```__tests__``` folder and all the test files will be added with `.test.ts` extension. This will also generate the jest config and jest setup files if not exists, But if exists then it won't be re-generated.

Now, if we consider our example then the folder structure will be as follows:

```js
- app/
  - screens/
    - __tests__
      - Home.test.ts
      - Dashboard.test.ts
      - Drawer.test.ts
    - Home.ts
    - Dashboard.ts
    - Drawer.ts
```

## Next Steps?

- If generator had created the jest config and jest setup files then we would suggest you to go through those files and map the imports and test linkings properly in the setup file as per your package dependencies. Also move your setup, config files to root level.
- If your package doesn't provide the test cases link then simply comment that particular dependency in setup file (If you get error from that dependency then make sure you find a way to get test case link to add the setup).
- This will also generate Image Mock file which will be generated based on the active path that you are on. Make sure to move this `__mocks__` folder at root level.
- Run jest test in your generated folder and make sure everything is working as expected.
- Any error can be resolved by specifying defaultProps, if no defaultProps are passed propTypes will be parsed to try to generate fake data. Fake Data generation from propTypes is a WIP.
To write seamless and predictable tests add defaultProps to your component definitions.

## Conflicts

By default it won't overwrite anything without asking you first. So don't worry on existing test cases for the same component.

## Example

You can find this under the `example` folder of the project. Please feel free to give your suggestions.

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