forked from expressjs/express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppRoutesError.mjs
63 lines (54 loc) · 1.45 KB
/
AppRoutesError.mjs
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
'use strict'
import { describe, it } from 'node:test'
import express from '../lib/express.js'
import assert from 'node:assert'
import request from 'supertest'
describe('app', () => {
describe('.VERB()', () => {
it('should not get invoked without error handler on error', (t, done) => {
const app = express()
app.use((req, res, next) => {
next(new Error('boom!'))
})
app.get('/bar', (req, res) => {
res.send('hello, world!')
})
request(app)
.post('/bar')
.expect(500, /Error: boom!/, done)
})
it('should only call an error handling routing callback when an error is propagated', (t, done) => {
const app = express()
let a = false
let b = false
let c = false
let d = false
app.get('/', (req, res, next) => {
next(new Error('fabricated error'))
}, (req, res, next) => {
a = true
next()
}, (err, req, res, next) => {
b = true
assert.strictEqual(err.message, 'fabricated error')
next(err)
}, (err, req, res, next) => {
c = true
assert.strictEqual(err.message, 'fabricated error')
next()
}, (err, req, res, next) => {
d = true
next()
}, (req, res) => {
assert.ok(!a)
assert.ok(b)
assert.ok(c)
assert.ok(!d)
res.sendStatus(204)
})
request(app)
.get('/')
.expect(204, done)
})
})
})