• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import { paramMock } from "./utils"
2
3export function mockDocument() {
4  global.systemplugin.document = {
5    create: function (...args) {
6      console.warn("document.create interface mocked in the Previewer. How this interface works on the Previewer may" +
7        " be different from that on a real device.")
8      const len = args.length
9      if (typeof args[len - 1] === 'function') {
10        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
11      } else {
12        return new Promise((resolve, reject) => {
13          resolve(paramMock.paramStringMock);
14        })
15      }
16    },
17    choose: function (...args) {
18      console.warn("document.choose interface mocked in the Previewer. How this interface works on the Previewer may" +
19        " be different from that on a real device.")
20      const len = args.length
21      if (typeof args[len - 1] === 'function') {
22        args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock)
23      } else {
24        return new Promise((resolve, reject) => {
25          resolve(paramMock.paramStringMock);
26        })
27      }
28    },
29    show: function (...args) {
30      console.warn("document.show interface mocked in the Previewer. How this interface works on the Previewer may" +
31        " be different from that on a real device.")
32      const len = args.length
33      if (typeof args[len - 1] === 'function') {
34        args[len - 1].call(this, paramMock.businessErrorMock)
35      } else {
36        return new Promise((resolve, reject) => {
37          resolve();
38        })
39      }
40    }
41  }
42}