Reactjs 模拟电容器与笑话反应
我试图用ionic react模拟电容器插件:Reactjs 模拟电容器与笑话反应,reactjs,typescript,ionic-framework,capacitor,capacitor-plugin,Reactjs,Typescript,Ionic Framework,Capacitor,Capacitor Plugin,我试图用ionic react模拟电容器插件: import { ICreateAccountAction } from "../../framework/auth/interfaces/ICreateAccountAction"; import { Plugins } from '@capacitor/core'; import oauthCreateAccountConfig from "../../config/azure/oauth_register.jso
import { ICreateAccountAction } from "../../framework/auth/interfaces/ICreateAccountAction";
import { Plugins } from '@capacitor/core';
import oauthCreateAccountConfig from "../../config/azure/oauth_register.json"
import { CreateAccountResult } from "../../framework/auth/result/CreateAccountResult";
import { AuthError } from "../../framework/auth/exceptions/AuthError";
export class CreateAccount implements ICreateAccountAction {
async execute() {
try {
const response = await Plugins.OAuth2Client.authenticate(oauthCreateAccountConfig)
let accessToken = response["access_token"];
let refreshToken = response["refresh_token"];
return new CreateAccountResult(accessToken, refreshToken)
} catch (error) {
throw new AuthError(error)
}
}
}
我想模拟从'@capactor/core'导入{Plugins}代码>
我试过:
describe("CreateAccount", () => {
describe("#execute", () => {
test("return `CreateAccountResult`", async () => {
jest.mock('@capacitor/core', () => ({ Plugins: () => { return "" } }))
const uat = new CreateAccount()
const result = await uat.execute()
expect(result).toBeInstanceOf(CreateAccountResult)
})
})
})
模拟文件夹
我也试过使用uuuuumocks uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
export const Plugins={}代码>
但我还是会
OAuth2Client没有web实现。
这意味着模拟没有起作用
也尝试过:
export const Plugins = {
OAuth2Client: () => jest.fn()
};