Skip to content

Commit 74715fa

Browse files
committed
🌿 Add test for calling method that fails internally
1 parent 98ba3ef commit 74715fa

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

tests/denops/runtime/functions/denops/request_async_test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,40 @@ testHost({
115115
);
116116
});
117117

118+
await t.step("if the dispatcher method throws an error", async (t) => {
119+
await t.step("returns immediately", async () => {
120+
await host.call("execute", [
121+
"let g:__test_denops_events = []",
122+
"call denops#request_async('dummy', 'fail', ['foo'], 'TestDenopsRequestAsyncSuccess', 'TestDenopsRequestAsyncFailure')",
123+
"let g:__test_denops_events_after_called = g:__test_denops_events->copy()",
124+
], "");
125+
126+
assertEquals(
127+
await host.call("eval", "g:__test_denops_events_after_called"),
128+
[],
129+
);
130+
});
131+
132+
await t.step("calls failure callback", async () => {
133+
await wait(() => host.call("eval", "len(g:__test_denops_events)"));
134+
assertObjectMatch(
135+
await host.call("eval", "g:__test_denops_events") as unknown[],
136+
{
137+
0: [
138+
"TestDenopsRequestAsyncFailure:Called",
139+
[
140+
{
141+
message:
142+
"Failed to call 'fail' API in 'dummy': Dummy failure",
143+
name: "Error",
144+
},
145+
],
146+
],
147+
},
148+
);
149+
});
150+
});
151+
118152
await t.step("if the dispatcher method is not exist", async (t) => {
119153
await t.step("returns immediately", async () => {
120154
await host.call("execute", [

tests/denops/runtime/functions/denops/request_test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ testHost({
6666
assertEquals(result, { result: "OK", args: ["foo"] });
6767
});
6868

69+
await t.step("if the dispatcher method throws an error", async (t) => {
70+
await t.step("throws an error", async () => {
71+
await assertRejects(
72+
() =>
73+
host.call(
74+
"denops#request",
75+
"dummy",
76+
"fail",
77+
["foo"],
78+
),
79+
Error,
80+
"Failed to call 'fail' API in 'dummy': Dummy failure",
81+
);
82+
});
83+
});
84+
6985
await t.step("if the dispatcher method is not exist", async (t) => {
7086
await t.step("throws an error", async () => {
7187
await assertRejects(

tests/denops/testdata/dummy_dispatcher_plugin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ export const main: Entrypoint = (denops) => {
1414
);
1515
return { result: "OK", args };
1616
},
17+
fail: async () => {
18+
await delay(MIMIC_DISPATCHER_METHOD_DELAY);
19+
throw new Error("Dummy failure");
20+
},
1721
};
1822
};

0 commit comments

Comments
 (0)