diff --git a/mod.ts b/mod.ts index 5a717e3..063dacf 100644 --- a/mod.ts +++ b/mod.ts @@ -32,7 +32,7 @@ export class EnvNotSetError extends Error { /** * @param envVariable name of the environment variable */ - constructor(envVariable: string, cause?: unknown) { + constructor(public readonly envVariable: string, cause?: unknown) { super( `Environment variable ${envVariable} is not set.\n` + `You can also set it by specifying a path to a file ` + diff --git a/mod_test.ts b/mod_test.ts index 477beb3..80d2919 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -60,17 +60,57 @@ const REQUIRED_FAILING = { Deno.test("EnvNotSetError", async (t) => { await t.step("without cause", () => { const err = new EnvNotSetError("TEST"); - assertStringIncludes(err.message, "TEST"); - assertStringIncludes(err.message, "TEST_FILE"); - assertIsError(err); + assertStringIncludes( + err.message, + "TEST", + "Expected the message to contain the env variable name", + ); + assertStringIncludes( + err.message, + "TEST_FILE", + "Expected the message to contain a note about setting the variable using TEST_FILE", + ); + assertEquals( + err.envVariable, + "TEST", + "Expected the envVariable to be set correctly", + ); + assertIsError( + err, + EnvNotSetError, + undefined, + "Expected the error to be an Error instance of EnvNotSetError", + ); }); await t.step("with cause", () => { const err = new EnvNotSetError("TEST", new Error("cause")); - assertStringIncludes(err.message, "TEST"); - assertStringIncludes(err.message, "TEST_FILE"); - assertEquals(err.cause, new Error("cause")); - assertIsError(err); + assertStringIncludes( + err.message, + "TEST", + "Expected the message to contain the env variable name", + ); + assertStringIncludes( + err.message, + "TEST_FILE", + "Expected the message to contain a note about setting the variable using TEST_FILE", + ); + assertEquals( + err.envVariable, + "TEST", + "Expected the envVariable to be set correctly", + ); + assertEquals( + err.cause, + new Error("cause"), + "Expected the cause to be set correctly", + ); + assertIsError( + err, + EnvNotSetError, + undefined, + "Expected the error to be an Error instance of EnvNotSetError", + ); }); });