Skip to content

Commit b39ea68

Browse files
committed
test: add a test case of async func
1 parent da4e223 commit b39ea68

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/index.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,42 @@ describe("evalCode", () => {
218218
arena.dispose();
219219
ctx.dispose();
220220
});
221+
222+
test("async function", async () => {
223+
const ctx = (await getQuickJS()).newContext();
224+
const arena = new Arena(ctx, { isMarshalable: true });
225+
226+
const consolelog = vi.fn();
227+
arena.expose({
228+
console: {
229+
log: consolelog,
230+
},
231+
});
232+
233+
arena.evalCode(`
234+
const someAsyncOperation = async () => "hello";
235+
const execute = async () => {
236+
try {
237+
const res = await someAsyncOperation();
238+
console.log(res);
239+
} catch (e) {
240+
console.log(e);
241+
}
242+
};
243+
execute();
244+
`);
245+
expect(consolelog).toBeCalledTimes(0);
246+
expect(arena.executePendingJobs()).toBe(2);
247+
248+
arena.executePendingJobs();
249+
250+
expect(consolelog).toBeCalledTimes(1);
251+
expect(consolelog).toBeCalledWith("hello");
252+
expect(arena.executePendingJobs()).toBe(0);
253+
254+
arena.dispose();
255+
ctx.dispose();
256+
});
221257
});
222258

223259
describe("expose without sync", () => {

0 commit comments

Comments
 (0)