Skip to content

Commit b75d95a

Browse files
committed
fix(response): Ensure statusCode is correctly set
IE checks if `status` was set in `options` and used the value without checking it. This resulted in a bug, where `status` in `Response` was `undefined` in IE
1 parent 51282b0 commit b75d95a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/yet-another-fetch-mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class FetchMock {
101101
)
102102
)
103103
.then(
104-
({ body, status, statusText, headers }: ResponseData) =>
104+
({ body, status = 200, statusText = 'OK', headers = {} }: ResponseData) =>
105105
new Response(body, { status, statusText, headers })
106106
);
107107
}

test/yet-another-fetch-mock.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ describe('FetchMock', () => {
4848
});
4949
});
5050

51+
it('should should set statusCode and statusText', done => {
52+
mock.get('/status', { key: 'value' });
53+
fetch('/status').then(resp => {
54+
expect(resp.status).toBe(200);
55+
expect(resp.statusText).toBe('OK');
56+
expect(resp.ok).toBe(true);
57+
done();
58+
});
59+
});
60+
5161
it('should pass along body, path-params and query-params', done => {
5262
const payload = { payload: 'my custom payload' };
5363
mock.post('/test/:id/:app', (args: HandlerArgument) => {
@@ -129,7 +139,7 @@ describe('FetchMock', () => {
129139

130140
expect(() => {
131141
fetchToJson('/test');
132-
}).toThrow();
142+
}).toThrow(`Did not find any matching route for url: /test`);
133143
});
134144

135145
it('should throw on unknown url type', () => {

0 commit comments

Comments
 (0)