Skip to content

Commit

Permalink
capricorn86#452@patch: Fix Response constructor issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
kombucha committed Jul 17, 2022
1 parent c676188 commit 0ea2a8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/happy-dom/src/fetch/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ export default class Response extends NodeFetch.Response implements IResponse {

/**
* Constructor.
*
* @param [body] An object defining a body for the response (can be omitted)
* @param [init] An options object containing any custom settings that you want to apply to the response, or an empty object (which is the default value)
*/
constructor() {
super();
constructor(body?: NodeFetch.BodyInit, init?: NodeFetch.ResponseInit) {
super(body, init);
this._ownerDocument = (<typeof Response>this.constructor)._ownerDocument;
}

Expand Down
22 changes: 22 additions & 0 deletions packages/happy-dom/test/fetch/Response.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Response from '../../src/fetch/Response';
import Window from '../../src/window/Window';

jest.unmock('node-fetch');

beforeAll(() => {
const window = new Window();
Response._ownerDocument = window.document;
});

afterAll(() => {
Response._ownerDocument = null;
});

describe('Response', () => {
it('Forwards constructor arguments to base implementation.', async () => {
const response = new Response('hello there', { status: 404 });

expect(response.status).toBe(404);
expect(await response.text()).toBe('hello there');
});
});

0 comments on commit 0ea2a8b

Please sign in to comment.