!101 add statfs js api mock

Merge pull request !101 from shuzhouhao/OpenHarmony-3.1-Beta
This commit is contained in:
openharmony_ci
2022-01-17 07:27:58 +00:00
committed by Gitee
2 changed files with 34 additions and 0 deletions
@@ -34,6 +34,7 @@ import { mockWifi } from './wifi'
import { mockSettings } from './settings'
import { mockUri } from './uri'
import { mockXml } from './xml'
import { mockStatfs } from './statfs'
export function mockRequireNapiFun() {
global.requireNapi = function (...args) {
@@ -110,6 +111,8 @@ export function mockRequireNapiFun() {
return mockUri();
case "xml":
return mockXml();
case "statfs":
return mockStatfs();
default:
return global.requireNapiPreview(...args);
}
@@ -0,0 +1,31 @@
import { paramMock } from "../utils"
export function mockStatfs() {
const statfs = {
getFreeBytes: function (...args) {
console.warn("statfs.getFreeBytes interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramNumberMock);
})
}
},
getTotalBytes: function (...args) {
console.warn("statfs.getTotalBytes interface mocked in the Previewer. How this interface works on the" +
" Previewer may be different from that on a real device.")
const len = args.length
if (typeof args[len - 1] === 'function') {
args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock)
} else {
return new Promise((resolve, reject) => {
resolve(paramMock.paramNumberMock);
})
}
},
}
return statfs;
}