Giter Site home page Giter Site logo

miniprogram-simulate's Introduction

miniprogram-simulate

介绍

小程序自定义组件测试工具集。

目前因为小程序独特的运行环境,所以对于小程序自定义组件的单元测试一直没有比较优雅的解决方案,此工具集就是为了解决此痛点而诞生的。将原本小程序自定义组件双线程分离运行的机制调整成单线程模拟运行,利用 dom 环境进行渲染,借此来完成整个自定义组件树的搭建。

运行此工具集需要依赖 js 运行环境和 dom 环境,因此可以采用 jsdom + nodejs(如 jest),也可以采用真实浏览器环境(如 karma)。文档使用简介中会提供简单的使用方式介绍。

安装

npm install --save-dev miniprogram-simulate

使用

const simulate = require('miniprogram-simulate')

test('test sth', () => {
    const id = simulate.load('/components/comp/index') // 加载自定义组件
    const comp = simulate.render(id) // 渲染自定义组件
    
    // 使用自定义组件封装实例 comp 对象来进行各种单元测试
})

以上只是一个简单的例子,实际上这个工具集必须搭配 jest 或 jsdom/mocha 等测试框架来使用,更为详细的使用细节请参阅下述文档:

协议

MIT

miniprogram-simulate's People

Contributors

genuifx avatar imyelo avatar juneandgreen avatar xuemuyang avatar

Watchers

 avatar  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.