|
6 | 6 | returnsNext, |
7 | 7 | spy, |
8 | 8 | } from "@std/testing/mock"; |
| 9 | +import { flushPromises } from "@core/asyncutil"; |
9 | 10 | import { assert, is } from "@core/unknownutil"; |
10 | 11 | import { test } from "@denops/test"; |
11 | 12 | import { expr, rawString } from "../eval/mod.ts"; |
@@ -72,16 +73,23 @@ test({ |
72 | 73 | }); |
73 | 74 | await t.step("if 'once' option is specified", async (t) => { |
74 | 75 | await t.step("registers an oneshot lambda function", async (t) => { |
75 | | - const fn = spy(returnsNext(["foo"])); |
| 76 | + const waiter = Promise.withResolvers<void>(); |
| 77 | + const fn = spy(resolvesNext([waiter.promise.then(() => "foo")])); |
76 | 78 | const id = lambda.register(denops, fn, { once: true }); |
77 | 79 | assertSpyCalls(fn, 0); |
78 | | - assertEquals(await denops.dispatch(denops.name, id), "foo"); |
| 80 | + |
| 81 | + // Call the lambda function twice before the first call resolves |
| 82 | + const firstCall = denops.dispatch(denops.name, id); |
| 83 | + const secondCall = denops.dispatch(denops.name, id); |
| 84 | + secondCall.catch(NOOP); |
| 85 | + await flushPromises(); |
| 86 | + waiter.resolve(); |
| 87 | + |
| 88 | + assertEquals(await firstCall, "foo"); |
79 | 89 | assertSpyCalls(fn, 1); |
80 | 90 |
|
81 | 91 | await t.step("which will be removed if called once", async () => { |
82 | | - const error = await assertRejects( |
83 | | - () => denops.dispatch(denops.name, id), |
84 | | - ); |
| 92 | + const error = await assertRejects(() => secondCall); |
85 | 93 | assertStringIncludes( |
86 | 94 | error as string, |
87 | 95 | "denops.dispatcher[name] is not a function", |
|
0 commit comments