search
HomeWeChat AppletMini Program DevelopmentShare some common auxiliary testing functions of WeChat mini programs: chance

What we are going to introduce is a WeChat applet auxiliary testing tool: Chance! Chance is a JavaScript random number generation tool. When we test some functions of the applet, we may need some random phone numbers, zip codes, names. Chance can generate random numbers, bytes, characters, namespaces, and addresses. , Dictionary Waiting, helps better automated testing. Chance is an open source software released under the MIT license that is friendly to both development and commercial use.

Chance Use

to randomly generate basic data:

    console.log(chance.bool()); // 输出:false
    console.log(chance.character()); // 输出:I
    console.log(chance.floating()); // 输出:246585506136.064
    console.log(chance.integer()); // 输出:1867472378527744
    console.log(chance.natural()); // 输出:3524803082321920
    console.log(chance.string()); // 输出:7IVZVkvg2dLI@IP91C@V


Randomly generated text:

console.log(chance.paragraph());

Randomly generated phone number:

console.log(chance.paragraph());


Randomly generated zip code:

console.log(chance.zip()); // 76750

Randomly generate GUID:

console.log(chance.guid()); // 67f55bf2- 820d-5df8-98c8-a99cda4981daMock.js

Mock.js can generate random data and intercept Ajax requests

Functions implemented by Mock.js:

  • Generate data based on data template

  • Generate data based on HTML template

  • Intercept and simulate Ajax requests

Mock.js use

Use Mock

Common methods:

Generate simulated data based on the data template.

Mock.mock( rurl?, rtype?, template|function(options) )

The meaning and default value of the parameters are as follows:

  • rurl: Optional. Indicates the URL that needs to be intercepted, which can be a URL string or a URL regular. For example /\/domain\/list.json/, '/domian/list.json'.

  • rtype: Optional. Indicates the type of Ajax request that needs to be intercepted. For example GET, POST, PUT, DELETE, etc.

  • template: Optional. Represents a data template, which can be an object or a string. For example { ‘data|1-10’:[{}] }, ‘@EMAIL’.

  • function(options): Optional. Represents a function used to generate response data.

  • options: Points to the Ajax option set for this request.

#Configure the behavior when intercepting Ajax requests.

Mock.setup(settings)

Supported configuration items are: timeout.

Mock.Random is a tool class used to generate various random data.

Mock.Random

Verify whether the real data data matches the data template template.

Mock.valid(template, data)

Convert the Mock.js style data template template into JSON Schema.

Mock.toJSONSchema(template)Reference material

  • Chance

  • Chance@ github

  • Mock.js

  • Mock.js@github

  • Use Mock.js Front-end development independent of back-end

  • WeChat Mini Program Tips: Use mock.js to provide simulated data

The above is the detailed content of Share some common auxiliary testing functions of WeChat mini programs: chance. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.