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!