0.0.34 • Published 2 years ago

@mpflow/plugin-unit-test v0.0.34

Weekly downloads
21
License
MIT
Repository
github
Last release
2 years ago

@mpflow/plugin-unit-test

Mpflow 的小程序单元测试支持插件

说明

该插件用于给 Mpflow 的构架提供单元测试功能的集成,,使用 jest 为测试执行器,miniprogram-simulate 为自动化执行器

miniprogram-simulate 是通过模拟小程序的运行环境,让小程序的自定义组件能够在 DOM 环境下进行测试。因此适用于对单一组件进行单元测试,而不适用与对整个小程序进行集成测试

安装

mpflow add unit-test
# 或
mpflow add @mpflow/plugin-unit-test

使用

在自定义组件目录下新增 __test__ 文件夹,在文件夹下添加测试文件,如:

// comp.test.js

import path from 'path'
import simulate from 'miniprogram-simulate'

describe('comp', () => {
    let id

    beforeAll(() => {
        id = simulate.load(path.resolve(__dirname, '../comp'), { less: true })
    })

    test('should match snapshot', () => {
        const comp = simulate.render(id, {})
        comp.attach(document.createElement('parent-wrapper'))

        expect(comp.toJSON()).toMatchSnapshot()
    })
})

然后执行命令启动单元测试

npm run test:unit
# 或
yarn test:unit

也可以通过 --coverage 参数来获取代码覆盖率报告

npm run test:unit -- --coverage
# 或
yarn test:unit --coverage
0.0.34

2 years ago

0.0.33

3 years ago

0.0.30

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.24

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

5 years ago

0.0.16

5 years ago

0.0.17

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.12

5 years ago

0.0.13

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.1

5 years ago