Kylin-plugin-mock is a data mock plug-in developed for debugging JSAPI errors in the desktop browser (Google Chrome).
Enable the plug-in
Execute the following statement in the scaffold project, which is equivalent to the action of adding --mock
during command execution:
cnpm run dev:mock
Use the plug-in
The ./mock/mock.config.js
file of the project contains the following configurations:
const config = {};
// The custom mock.
config.call = {
// The mock rpc API.
rpc: function (opts, callback) {
var type = opts.operationType;
var rpc = require('./rpc/' + type);
var data = typeof rpc === 'function' ? rpc(opts) : rpc;
// Prevent the input object from being modified in the service logic.
data = Object.assign({}, data);
// Simulate a server/network interface delay. Two logs are recorded. One is for the request, and the other contains the return result.
setTimeout(() => {
callback && callback(data);
}, 2000);
},
}
window.lunaMockConfig = config;
The preceding configuration maps data for APIs in ./mock/rpc/*.js
.
Examples
After cnpm run dev:mock
is executed, the system enters the mock
mode. In this mode, execute AlipayJSBridge.call('abc')
in the browser to search for the mock API data in ./mock/jsapi/abc.js
.