Skip to content

Commit 364312b

Browse files
committed
test: improve tests
1 parent 6f9fb98 commit 364312b

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

lib/loader.spec.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,10 @@ describe("TypeScriptLoader", () => {
5959
});
6060

6161
it("should throw a TypeScriptCompileError on error", async () => {
62-
try {
63-
const filePath = path.resolve(fixturesPath, "invalid.fixture.ts");
64-
await loader(filePath, readFixtureContent(filePath));
65-
fail(
66-
"Error should be thrown upon failing to transpile an invalid TS file.",
67-
);
68-
} catch (error: unknown) {
69-
expect(error).toBeInstanceOf(TypeScriptCompileError);
70-
}
62+
const filePath = path.resolve(fixturesPath, "invalid.fixture.ts");
63+
await expect(
64+
loader(filePath, readFixtureContent(filePath)),
65+
).rejects.toThrow(TypeScriptCompileError);
7166
});
7267

7368
describe("jiti", () => {
@@ -86,7 +81,7 @@ describe("TypeScriptLoader", () => {
8681

8782
it("rethrows an error if it is not an instance of Error", async () => {
8883
try {
89-
await loader("filePath", "readFixtureContent(filePath)");
84+
await loader("filePath", "invalidInput");
9085
fail(
9186
"Error should be thrown upon failing to transpile an invalid TS file.",
9287
);
@@ -126,15 +121,10 @@ describe("TypeScriptLoader", () => {
126121
});
127122

128123
it("should throw a TypeScriptCompileError on error", () => {
129-
try {
130-
const filePath = path.resolve(fixturesPath, "invalid.fixture.ts");
131-
loader(filePath, readFixtureContent(filePath));
132-
fail(
133-
"Error should be thrown upon failing to transpile an invalid TS file.",
134-
);
135-
} catch (error: unknown) {
136-
expect(error).toBeInstanceOf(TypeScriptCompileError);
137-
}
124+
const filePath = path.resolve(fixturesPath, "invalid.fixture.ts");
125+
expect((): unknown =>
126+
loader(filePath, readFixtureContent(filePath)),
127+
).toThrow(TypeScriptCompileError);
138128
});
139129

140130
describe("jiti", () => {
@@ -152,7 +142,7 @@ describe("TypeScriptLoader", () => {
152142

153143
it("rethrows an error if it is not an instance of Error", () => {
154144
try {
155-
loader("filePath", "readFixtureContent(filePath)");
145+
loader("filePath", "invalidInput");
156146
fail(
157147
"Error should be thrown upon failing to transpile an invalid TS file.",
158148
);

0 commit comments

Comments
 (0)