deno.land / x / opine@2.3.4 / test / units / app.routes.error.test.ts

app.routes.error.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { opine } from "../../mod.ts";import { expect, superdeno } from "../deps.ts";import { describe, it } from "../utils.ts";import type { NextFunction, OpineRequest, OpineResponse,} from "../../src/types.ts";
describe("app", function () { describe(".VERB()", function () { it("should not get invoked without error handler on error", function ( done, ) { const app = opine();
app.use(function (req, res, next) { next(new Error("boom!")); });
app.get("/bar", function (req, res) { res.send("hello, world!"); });
superdeno(app) .post("/bar") .expect(500, /Error: boom!/, done); });
it( "should only call an error handling routing callback when an error is propagated", function ( done, ) { const app = opine();
let a = false; let b = false; let c = false; let d = false;
app.get( "/", function (req, res, next) { next(new Error("fabricated error")); }, function (req, res, next) { a = true; next(); }, function ( err: any, req: OpineRequest, res: OpineResponse, next: NextFunction, ) { b = true; expect(err.message).toEqual("fabricated error"); next(err); }, function ( err: any, req: OpineRequest, res: OpineResponse, next: NextFunction, ) { c = true; expect(err.message).toEqual("fabricated error"); next(); }, function ( err: any, req: OpineRequest, res: OpineResponse, next: NextFunction, ) { d = true; next(); }, function (req, res) { expect(a).toBe(false); expect(b).toBe(true); expect(c).toBe(true); expect(d).toBe(false); res.sendStatus(204); }, );
superdeno(app) .get("/") .expect(204, done); }, ); });});
opine

Version Info

Tagged at
2 years ago