# finance-unit-test

> ### 使用方式

Latest version **1.0.4** (published 2019-09-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install finance-unit-test
pnpm add finance-unit-test
yarn add finance-unit-test
bun add finance-unit-test
```

Provides the command `finance-unit-test`.

## 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.4 |
| Published | 2019-09-25 |
| First published | 2019-08-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 16.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | zuoguangcheng |
| Maintainers | zuoguangcheng |

## Links

- npm: https://www.npmjs.com/package/finance-unit-test
- npm.io page: https://npm.io/package/finance-unit-test

## Dependencies (10)

- [jest](https://npm.io/package/jest.md) ^24.9.0
- [enzyme](https://npm.io/package/enzyme.md) ^3.10.0
- [babel-jest](https://npm.io/package/babel-jest.md) ^24.9.0
- [jest-fetch-mock](https://npm.io/package/jest-fetch-mock.md) ^2.1.2
- [react-test-renderer](https://npm.io/package/react-test-renderer.md) ^16.8.6
- [jest-watch-typeahead](https://npm.io/package/jest-watch-typeahead.md) ^0.4.0
- [babel-preset-react-app](https://npm.io/package/babel-preset-react-app.md) ^9.0.1
- [jest-localstorage-mock](https://npm.io/package/jest-localstorage-mock.md) ^2.4.0
- [enzyme-adapter-react-16](https://npm.io/package/enzyme-adapter-react-16.md) ^1.14.0
- [@testing-library/jest-dom](https://npm.io/package/@testing-library/jest-dom.md) ^4.1.0

## Recent versions

- 1.0.4 (latest) — 2019-09-25
- 1.0.2 — 2019-09-06
- 1.0.1 — 2019-09-06
- 1.0.0 — 2019-08-30

## README

### 单元测试配置集成
  

### 使用方式

step1

```
    npm install --save-dev finance-unit-test
```

step2

```
 在package.json 中添加一条script语句：  "test": "finance-unit-test"。
 
 可以配置cli参数；  
 eg："test": "finance-unit-test --watchAll"。
 cli 参数文档 https://jestjs.io/docs/zh-Hans/cli
  
```

step3

```
在项目src 下创建 __test__ 文件夹，在该文件夹下编写测试用例

tip:建议测试用例写在__test__ 文件夹下，实际上在./src下任何一个地方都可以写测试用例。
./src 目录位置在config.roots字段中可以配置
```


### 说明

 1.如若修改或添加jest配置, 可以在项目跟目录下config 目录下可以配置jest.config.js文件，内容如下
  
  ```
    module.exports = (defaultConfig) => {
        console.log('defaultConfig', defaultConfig);
        return defaultConfig;
    }
  ```

  defaultConfig可以查看所有的默认配置，这里可以更改所有的jest配置。  
  jest 配置文档 https://jestjs.io/docs/en/configuration
  
  2.earth-script项目文件引入会使用webpack中的alias功能，在jest配置文件中也会默认使用config/alias.js中的文件映射，具体配置可以查看defaultConfig.moduleNameMapper
  
  3.引入enzyme中的mount、shallow、render 方法可以直接通过 import { mount, render, shallow } from 'finance-unit-test';方式引用。
  
### 例子
    ```
        1.引入React 
        import React from 'react'
        2.引入需要测试的组件
        import Component from '../path/Component'
        3.引入组件的渲染方式
        import { shallow } from 'finance-unit-test';
        
        4.正式写测试用例
        
        describe('test Component', () => {
             beforeEach(() => {
                // 需要在执行每个case之前作出的处理
                fetch.resetMocks();
             })；
             
             beforeAll(() => {
                 // 需要在执行所有case之前作出的处理
             })
             
             afterEach(() => {
                
             })
             
             afterAll(() => {1
                
             })
                
            it('组件正常渲染', () => {
                const wrapper = shallow(<Component />);
                expect(wrapper.find('.class')).toHaveBeenLengh(1);
            })
        })
    ```
    
### 项目地址
    http://igit.58corp.com/58finance_fed/finance-unit-test
    
### 测试用例demo地址
    https://github.com/Zuoguangcheng/reactUnitExample
    
    
### 版本记录

#### V1.0.3
     1.init
     
#### V1.0.4
     1.增加ts tsx支持
     2.增加webpack中alias在jest中的支持，默认使用config/alias.js中的映射

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