import { init } from '../../../src/web/app/tcb'; import * as CLOUD_SDK from '@cloudbase/weda-cloud-sdk'; describe('test web/app/tcb.ts', () => { afterEach(() => { // restore the spy created with spyOn jest.restoreAllMocks(); }); it('test init params=null', async () => { try { const initConfig = { /** 当前是否处于正式发布模式 */ isProd: false, /** 云开发环境ID */ envId: 'lowcode-9gu72kpiac8de2d6', login: () => {} } as any; const initTcbRes = { app: {} as any, auth: {} as any, } jest.spyOn(CLOUD_SDK, 'getTcbInstance').mockImplementation(async() => { return new Promise((resolve, reject) => { resolve(initTcbRes) }) }) await init(null as any); expect(CLOUD_SDK.getTcbInstance).toBeCalled(); } catch(err) {} }) it('test init type=portal', async () => { const initConfig = { /** 当前是否处于正式发布模式 */ isProd: false, type: 'portal', /** 云开发环境ID */ envId: 'lowcode-9gu72kpiac8de2d6', login: () => {} } const initTcbRes = { app: {} as any, auth: {} as any, } jest.spyOn(CLOUD_SDK, 'getTcbInstance').mockImplementation(async() => { return new Promise((resolve, reject) => { resolve(initTcbRes) }) }) const res = await init(initConfig); expect(res).toBeUndefined(); expect(CLOUD_SDK.getTcbInstance).toBeCalled(); }) })