import { IllusionCore } from '../core/illusion-core'; import { NormalServicer } from './normal-servicer'; import { MessageType } from '../core/message-type'; jest.mock('../core/illusion-core', () => { return { IllusionCore: jest.fn().mockImplementation(() => { return { do: jest.fn(() => 'result') }; }) }; }); jest.mock('../wasm/illusion.js'); describe('servicer/normalServicer', () => { beforeEach(() => { // @ts-ignore IllusionCore.mockClear(); }) it('正确的构造', () => { const normalService = new NormalServicer(); // @ts-ignore expect(IllusionCore.mock.calls.length).toBe(1); expect(normalService.illusionCore).toBeDefined(); }); it('发送指令并返回内容', async () => { const normalService = new NormalServicer(); const result = await normalService.do(MessageType.engine.init, ['/resources', true]); // @ts-ignore expect(normalService.illusionCore.do.mock.calls[0]).toEqual([MessageType.engine.init, ['/resources', true]]); expect(result).toBe('result'); }); it('测试销毁(无用)', () => { const normalService = new NormalServicer(); normalService.destory(); }); });