Skip to content

Commit

Permalink
Add tests for 404 page
Browse files Browse the repository at this point in the history
Signed-off-by: macdonst <[email protected]>
  • Loading branch information
macdonst committed Jul 23, 2024
1 parent f25c4bc commit 3119a9b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/mock-errors/app/pages/404.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function FourOhFour ({ html, state }) {
const { error } = state.attrs

return html`
<main>
<h1>Custom 404</h1>
<h2>Sorry we can't find that.</h2>
<p>${error && error}</p>
</main>
`
}
38 changes: 38 additions & 0 deletions test/router-error-codes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import test from 'tape'
import url from 'url'
import path from 'path'
import router from '../src/http/any-catchall/router.mjs'

const __dirname = path.dirname(url.fileURLToPath(import.meta.url))

test('test default 404 page', async t => {
t.plan(2)
let req = {
rawPath: '/nope',
method: 'GET',
headers: {
'accept': 'text/html'
}
}
let base = path.join(__dirname, 'mock-folders', 'app')
let result = await router({ basePath: base }, req)
t.ok(result, 'got result')
t.equal(result.status, 404, 'Default 404 page')
console.log(result)
})

test('overridden 404 page', async t => {
t.plan(2)
let req = {
rawPath: '/nope',
method: 'GET',
headers: {
'accept': 'text/html'
}
}
let base = path.join(__dirname, 'mock-errors', 'app')
let result = await router({ basePath: base }, req)
t.ok(result.html.includes('Custom 404'), 'got result')
t.equal(result.status, 404, 'Overridden 404 page')
console.log(result)
})

0 comments on commit 3119a9b

Please sign in to comment.