All Products
Search
Document Center

mock

Last Updated: Jul 16, 2021

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:

 
  1. cnpm run dev:mock

Use the plug-in

The ./mock/mock.config.js file of the project contains the following configurations:

 
  1. const config = {};
  2. // The custom mock.
  3. config.call = {
  4. // The mock rpc API.
  5. rpc: function (opts, callback) {
  6. var type = opts.operationType;
  7. var rpc = require('./rpc/' + type);
  8. var data = typeof rpc === 'function' ? rpc(opts) : rpc;
  9. // Prevent the input object from being modified in the service logic.
  10. data = Object.assign({}, data);
  11. // Simulate a server/network interface delay. Two logs are recorded. One is for the request, and the other contains the return result.
  12. setTimeout(() => {
  13. callback && callback(data);
  14. }, 2000);
  15. },
  16. }
  17. 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.