Files
bun.sh/test/js/bun/shell/throw.test.ts
2024-09-03 21:32:52 -07:00

51 lines
1.1 KiB
TypeScript

import { $ } from "bun";
import { beforeAll, describe, expect, test } from "bun:test";
beforeAll(() => {
$.nothrow();
});
describe("throw", () => {
test("enabled globally", async () => {
$.throws(true);
let e;
try {
await $`ls ksjflkjfksjdflksdjflksdf`;
expect("Woops").toBe("Should have thrown");
} catch (err) {
e = err;
}
expect(e).toBeDefined();
});
test("enabled locally", async () => {
let e;
try {
await $`ls ksjflkjfksjdflksdjflksdf`.throws(true);
expect("Woops").toBe("Should have thrown");
} catch (err) {
e = err;
}
expect(e).toBeDefined();
});
test("disable globally", async () => {
$.throws(true);
$.nothrow();
try {
await $`ls ksjflkjfksjdflksdjflksdf`;
} catch (err) {
expect("Woops").toBe("Should not have thrown");
}
});
test("disable locally", async () => {
$.throws(true);
try {
await $`ls ksjflkjfksjdflksdjflksdf`.nothrow();
} catch (err) {
expect("Woops").toBe("Should not have thrown");
}
});
});