Giter Site home page Giter Site logo

ra-lib's Introduction

ra-lib

通用工具、组件库。 查看文档

快速开始

初始化:从新安装依赖 + 打包

$ npm run init

安装依赖

$ npm i # 为项目安装依赖
$ npm run bootstrap # 为所有字包安装依赖

打包

$ npm run build

发布

$ npm run publish

打包 + 发布

$ npm run release

开发 本地调试

监听文件改变,单独构建对应包。

$ npm run start

调试,创建连接

$ cd packages/ajax
$ yarn link

# cd some/project
$ yarn link @ra-lib/ajax

所有包创建连接

node scripts/link-all.js

文档

开发环境文档预览

$ npm dev

文档打包

$ npm run docs:build

单元测试

测试框架

  • @umijs/test,测试脚本,内置 jest 测试框架
  • @testing-library/react,React 组件测试工具
  • puppeteer,Headless 浏览器工具,用于 E2E 测试。

测试约定

目录规范

.
├── package.json
├── packages
│   ├── bs-components
│   │   └── src
│   │       └── YsHeader
│   │           └── __test__
│   │               └── index.test.tsx # 插件测试用例
├── tsconfig.json
├── .fatherrc.ts
└── yarn.lock

hooks 测试示例

import { renderHook, act } from '@testing-library/react-hooks';
import useTest from '../index';

const setUp = (defaultValue?: any) => renderHook(() => useTest(defaultValue));

describe('useTest', () => {
    it('should be defined', () => {
        expect(useTest).toBeDefined();
    });

    it('test on methods', async () => {
        const { result } = setUp(false);
        expect(result.current[0]).toBeFalsy();
        act(() => {
            result.current[1](true);
        });
        expect(result.current[0]).toBeTruthy();
    });
});

组件测试示例

import * as React from 'react';
import { render } from '@testing-library/react';
import TreeSelect from '../index';

test('TreeSelect test', () => {
    const wrapper = render(<TreeSelect/>);
    const el = wrapper.queryByText('pro-components TreeSelect');
    expect(el).toBeTruthy();
});

单元测试资料

  1. testing-library
  2. jests
  3. @testing-library/react
  4. @testing-library/react-hooks
  5. 学习 Jest——语法篇

ra-lib's People

Contributors

zkboys avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.