Skip to content

Commit

Permalink
🌿 Add test for calling method that fails internally
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Nov 26, 2024
1 parent 98ba3ef commit 74715fa
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/denops/runtime/functions/denops/request_async_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,40 @@ testHost({
);
});

await t.step("if the dispatcher method throws an error", async (t) => {
await t.step("returns immediately", async () => {
await host.call("execute", [
"let g:__test_denops_events = []",
"call denops#request_async('dummy', 'fail', ['foo'], 'TestDenopsRequestAsyncSuccess', 'TestDenopsRequestAsyncFailure')",
"let g:__test_denops_events_after_called = g:__test_denops_events->copy()",
], "");

assertEquals(
await host.call("eval", "g:__test_denops_events_after_called"),
[],
);
});

await t.step("calls failure callback", async () => {
await wait(() => host.call("eval", "len(g:__test_denops_events)"));
assertObjectMatch(
await host.call("eval", "g:__test_denops_events") as unknown[],
{
0: [
"TestDenopsRequestAsyncFailure:Called",
[
{
message:
"Failed to call 'fail' API in 'dummy': Dummy failure",
name: "Error",
},
],
],
},
);
});
});

await t.step("if the dispatcher method is not exist", async (t) => {
await t.step("returns immediately", async () => {
await host.call("execute", [
Expand Down
16 changes: 16 additions & 0 deletions tests/denops/runtime/functions/denops/request_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ testHost({
assertEquals(result, { result: "OK", args: ["foo"] });
});

await t.step("if the dispatcher method throws an error", async (t) => {
await t.step("throws an error", async () => {
await assertRejects(
() =>
host.call(
"denops#request",
"dummy",
"fail",
["foo"],
),
Error,
"Failed to call 'fail' API in 'dummy': Dummy failure",
);
});
});

await t.step("if the dispatcher method is not exist", async (t) => {
await t.step("throws an error", async () => {
await assertRejects(
Expand Down
4 changes: 4 additions & 0 deletions tests/denops/testdata/dummy_dispatcher_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ export const main: Entrypoint = (denops) => {
);
return { result: "OK", args };
},
fail: async () => {
await delay(MIMIC_DISPATCHER_METHOD_DELAY);
throw new Error("Dummy failure");
},
};
};

0 comments on commit 74715fa

Please sign in to comment.