Skip to content

Commit

Permalink
(#86) Improve fallback error type test case
Browse files Browse the repository at this point in the history
  • Loading branch information
predetermined authored Oct 19, 2021
2 parents 21df787 + 7c24464 commit fb49406
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion tests/uptests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import Aqua, {
valueMustBeOfType,
} from "../mod.ts";

const DEFAULT_NOT_FOUND_CONTENT = "Not found.";

const app = new Aqua(4000);
let registeredTests = 0;
let solvedTests = 0;
Expand Down Expand Up @@ -102,7 +104,7 @@ registerTest(
app.get("/api/v2/:action/:action2", (req) => req.parameters.action2);

const content = await requestContent(`/api/v2/hello/world/i`);
if (content !== "Not found.") {
if (content !== DEFAULT_NOT_FOUND_CONTENT) {
throw Error("URL parameters don't seem to work");
}
},
Expand Down Expand Up @@ -635,6 +637,22 @@ registerTest("Fallback handler error types working?", async () => {
`Expected fallback handler to return "SchemaMismatch". Instead got: ${content3}`,
);
}

app.provideFallback((_req, errorType) => {
switch (errorType) {
case ErrorType.ErrorThrownInResponseHandler:
return "ErrorThrownInResponseHandler";
default:
return null;
}
});

const content4 = await requestContent(route);
if (content4 !== DEFAULT_NOT_FOUND_CONTENT) {
throw new Error(
`Expected fallback handler to return "${DEFAULT_NOT_FOUND_CONTENT}". Instead got: ${content4}`,
);
}
});

setInterval(() => {
Expand Down

0 comments on commit fb49406

Please sign in to comment.