astro/packages/astro/test/ssr-404-500-pages.test.js
Matthew Phillips 714a8399e2
Return 404 status code for 404.astro in SSR (#4247)
* Return 404 status code for 404.astro in SSR

* Adding a changeset
2022-08-10 16:22:31 -04:00

49 lines
1.7 KiB
JavaScript

import { expect } from 'chai';
import { loadFixture } from './test-utils.js';
import testAdapter from './test-adapter.js';
import * as cheerio from 'cheerio';
describe('404 and 500 pages', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/ssr-api-route-custom-404/',
output: 'server',
adapter: testAdapter(),
});
await fixture.build({});
});
it('404 page returned when a route does not match', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/some/fake/route');
const response = await app.render(request);
expect(response.status).to.equal(404);
const html = await response.text();
const $ = cheerio.load(html);
expect($('h1').text()).to.equal('Something went horribly wrong!');
});
it('404 page returned when a route does not match and passing routeData', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/some/fake/route');
const routeData = app.match(request, { matchNotFound: true });
const response = await app.render(request, routeData);
expect(response.status).to.equal(404);
const html = await response.text();
const $ = cheerio.load(html);
expect($('h1').text()).to.equal('Something went horribly wrong!');
});
it('500 page returned when there is an error', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/causes-error');
const response = await app.render(request);
expect(response.status).to.equal(500);
const html = await response.text();
const $ = cheerio.load(html);
expect($('h1').text()).to.equal('This is an error page');
});
});