Skip to content

Commit 3119a9b

Browse files
committed
Add tests for 404 page
Signed-off-by: macdonst <simon.macdonald@gmail.com>
1 parent f25c4bc commit 3119a9b

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

test/mock-errors/app/pages/404.mjs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default function FourOhFour ({ html, state }) {
2+
const { error } = state.attrs
3+
4+
return html`
5+
<main>
6+
<h1>Custom 404</h1>
7+
<h2>Sorry we can't find that.</h2>
8+
<p>${error && error}</p>
9+
</main>
10+
`
11+
}

test/router-error-codes.mjs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import test from 'tape'
2+
import url from 'url'
3+
import path from 'path'
4+
import router from '../src/http/any-catchall/router.mjs'
5+
6+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url))
7+
8+
test('test default 404 page', async t => {
9+
t.plan(2)
10+
let req = {
11+
rawPath: '/nope',
12+
method: 'GET',
13+
headers: {
14+
'accept': 'text/html'
15+
}
16+
}
17+
let base = path.join(__dirname, 'mock-folders', 'app')
18+
let result = await router({ basePath: base }, req)
19+
t.ok(result, 'got result')
20+
t.equal(result.status, 404, 'Default 404 page')
21+
console.log(result)
22+
})
23+
24+
test('overridden 404 page', async t => {
25+
t.plan(2)
26+
let req = {
27+
rawPath: '/nope',
28+
method: 'GET',
29+
headers: {
30+
'accept': 'text/html'
31+
}
32+
}
33+
let base = path.join(__dirname, 'mock-errors', 'app')
34+
let result = await router({ basePath: base }, req)
35+
t.ok(result.html.includes('Custom 404'), 'got result')
36+
t.equal(result.status, 404, 'Overridden 404 page')
37+
console.log(result)
38+
})

0 commit comments

Comments
 (0)