import { mockClient, delay } from "@xmpp/test"; test("without resource", async () => { const resource = Math.random().toString(); const jid = "foo@bar/" + resource; const { entity } = mockClient(); entity.mockInput( , ); entity.scheduleIncomingResult( {jid} , ); const child = await entity.catchOutgoingSet(); expect(child).toEqual(); await delay(); expect(entity.jid.toString()).toBe(jid); }); test("with string resource", async () => { const resource = Math.random().toString(); const jid = "foo@bar/" + resource; const { entity } = mockClient({ resource }); entity.mockInput( , ); entity.scheduleIncomingResult( {jid} , ); const child = await entity.catchOutgoingSet(); expect(child).toEqual( {resource} , ); await delay(); expect(entity.jid.toString()).toBe(jid); }); test("with function resource", async () => { const resource = Math.random().toString(); const jid = "foo@bar/" + resource; const { entity } = mockClient({ resource: async () => { return resource; }, }); entity.mockInput( , ); entity.scheduleIncomingResult( {jid} , ); const child = await entity.catchOutgoingSet(); expect(child).toEqual( {resource} , ); await delay(); expect(entity.jid.toString()).toBe(jid); });