Skip to content

Commit

Permalink
test: added test for Response.error()
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Jul 24, 2024
1 parent 741fc13 commit c640f24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/core/src/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ export default class Router {
// eslint-disable-next-line class-methods-use-this
async generateResponse(callLog) {
const responseInput = await resolveUntilResponseConfig(callLog);

// If the response is a pre-made Response, respond with it
if (responseInput instanceof Response) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,21 @@ describe('response negotiation', () => {
});

it('Response', async () => {
fm.route(
'http://a.com/',
new fm.config.Response('http://a.com/', { status: 200 }),
);
fm.route('http://a.com/', new Response('http://a.com/', { status: 200 }));
const res = await fm.fetchHandler('http://a.com/');
expect(res.status).toEqual(200);
});

it('should work with Response.error()', async () => {
fm.route('http://a.com', Response.error());
const response = await fm.fetchHandler('http://a.com');
expect(response.status).toBe(0);
});

it('function that returns a Response', async () => {
fm.route(
'http://a.com/',
() => new fm.config.Response('http://a.com/', { status: 200 }),
() => new Response('http://a.com/', { status: 200 }),
);
const res = await fm.fetchHandler('http://a.com/');
expect(res.status).toEqual(200);
Expand All @@ -136,7 +139,7 @@ describe('response negotiation', () => {
it('Promise that returns a Response', async () => {
fm.route(
'http://a.com/',
Promise.resolve(new fm.config.Response('http://a.com/', { status: 200 })),
Promise.resolve(new Response('http://a.com/', { status: 200 })),
);
const res = await fm.fetchHandler('http://a.com/');
expect(res.status).toEqual(200);
Expand Down

0 comments on commit c640f24

Please sign in to comment.