test: add awaits to rejects and resolves
This commit is contained in:
parent
84d7da0195
commit
826dc1062a
4 changed files with 6 additions and 6 deletions
|
|
@ -55,7 +55,7 @@ describe("convert", () => {
|
||||||
|
|
||||||
test("should reject if execFile returns an error", async () => {
|
test("should reject if execFile returns an error", async () => {
|
||||||
mockExecFile = (cmd, args, callback) => callback(new Error("fail"), "", "");
|
mockExecFile = (cmd, args, callback) => callback(new Error("fail"), "", "");
|
||||||
expect(
|
await expect(
|
||||||
convert("input.yaml", "yaml", "json", "output.json", undefined, mockExecFile),
|
convert("input.yaml", "yaml", "json", "output.json", undefined, mockExecFile),
|
||||||
).rejects.toMatch(/error: Error: fail/);
|
).rejects.toMatch(/error: Error: fail/);
|
||||||
});
|
});
|
||||||
|
|
@ -63,7 +63,7 @@ describe("convert", () => {
|
||||||
test("should reject if writeFile fails", async () => {
|
test("should reject if writeFile fails", async () => {
|
||||||
// @ts-expect-error: property __promisify__ is missing
|
// @ts-expect-error: property __promisify__ is missing
|
||||||
fs.writeFile = (path, data, cb) => cb(new Error("write fail"));
|
fs.writeFile = (path, data, cb) => cb(new Error("write fail"));
|
||||||
expect(
|
await expect(
|
||||||
convert("input.yaml", "yaml", "json", "output.json", undefined, (cmd, args, cb) =>
|
convert("input.yaml", "yaml", "json", "output.json", undefined, (cmd, args, cb) =>
|
||||||
cb(null, "output-data", ""),
|
cb(null, "output-data", ""),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -108,14 +108,14 @@ test("strips leading './' from outdir", async () => {
|
||||||
// --- promise settlement ------------------------------------------------------
|
// --- promise settlement ------------------------------------------------------
|
||||||
test("resolves with 'Done' when execFile succeeds", async () => {
|
test("resolves with 'Done' when execFile succeeds", async () => {
|
||||||
behavior = { kind: "success", stdout: "fine", stderr: "" };
|
behavior = { kind: "success", stdout: "fine", stderr: "" };
|
||||||
expect(convert("in.txt", "txt", "docx", "out/out.docx", undefined, mockExecFile)).resolves.toBe(
|
await expect(convert("in.txt", "txt", "docx", "out/out.docx", undefined, mockExecFile)).resolves.toBe(
|
||||||
"Done",
|
"Done",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rejects when execFile returns an error", async () => {
|
test("rejects when execFile returns an error", async () => {
|
||||||
behavior = { kind: "error", message: "convert failed", stderr: "oops" };
|
behavior = { kind: "error", message: "convert failed", stderr: "oops" };
|
||||||
expect(convert("in.txt", "txt", "docx", "out/out.docx", undefined, mockExecFile)).rejects.toMatch(
|
await expect(convert("in.txt", "txt", "docx", "out/out.docx", undefined, mockExecFile)).rejects.toMatch(
|
||||||
/error: Error: convert failed/,
|
/error: Error: convert failed/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ describe("convert", () => {
|
||||||
|
|
||||||
test("should reject if execFile returns an error", async () => {
|
test("should reject if execFile returns an error", async () => {
|
||||||
mockExecFile = (cmd, args, callback) => callback(new Error("fail"), "", "");
|
mockExecFile = (cmd, args, callback) => callback(new Error("fail"), "", "");
|
||||||
expect(
|
await expect(
|
||||||
convert("input.md", "markdown", "html", "output.html", undefined, mockExecFile),
|
convert("input.md", "markdown", "html", "output.html", undefined, mockExecFile),
|
||||||
).rejects.toMatch(/error: Error: fail/);
|
).rejects.toMatch(/error: Error: fail/);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ describe("convert", () => {
|
||||||
|
|
||||||
test("should reject if execFile returns an error", async () => {
|
test("should reject if execFile returns an error", async () => {
|
||||||
mockExecFile = (cmd, args, callback) => callback(new Error("fail"), "", "stderr output");
|
mockExecFile = (cmd, args, callback) => callback(new Error("fail"), "", "stderr output");
|
||||||
expect(
|
await expect(
|
||||||
convert("input.png", "png", "svg", "output.svg", undefined, mockExecFile),
|
convert("input.png", "png", "svg", "output.svg", undefined, mockExecFile),
|
||||||
).rejects.toMatch(/error: Error: fail\nstderr: stderr output/);
|
).rejects.toMatch(/error: Error: fail\nstderr: stderr output/);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue