Skip to content

Commit

Permalink
xhr-fetch-polyfill: Minor test improvements (#26932)
Browse files Browse the repository at this point in the history
Expect console errors.
  • Loading branch information
mdmower committed Feb 24, 2020
1 parent 45f8fbb commit 601dd72
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions test/unit/test-xhr-fetch-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {createFormDataWrapper} from '../../src/form-data-wrapper';

describes.sandboxed('fetch', {}, env => {
describe('fetch method', () => {
const methodErrorRegex = /Only one of\s+GET, POST is currently allowed/;
let xhrCreated;

function setupMockXhr() {
Expand Down Expand Up @@ -63,6 +64,7 @@ describes.sandboxed('fetch', {}, env => {
});

it('should not allow PUT method', () => {
expectAsyncConsoleError(methodErrorRegex);
mockOkResponse();
return expect(
fetchPolyfill('/post', {
Expand All @@ -71,10 +73,11 @@ describes.sandboxed('fetch', {}, env => {
hello: 'world',
},
})
).to.be.rejectedWith(/Only one of GET, POST is currently allowed./);
).to.be.rejectedWith(methodErrorRegex);
});

it('should not allow PATCH method', () => {
expectAsyncConsoleError(methodErrorRegex);
mockOkResponse();
return expect(
fetchPolyfill('/post', {
Expand All @@ -83,10 +86,11 @@ describes.sandboxed('fetch', {}, env => {
hello: 'world',
},
})
).to.be.rejectedWith(/Only one of GET, POST is currently allowed./);
).to.be.rejectedWith(methodErrorRegex);
});

it('should not allow DELETE method', () => {
expectAsyncConsoleError(methodErrorRegex);
mockOkResponse();
return expect(
fetchPolyfill('/post', {
Expand All @@ -95,7 +99,7 @@ describes.sandboxed('fetch', {}, env => {
hello: 'world',
},
})
).to.be.rejectedWith(/Only one of GET, POST is currently allowed./);
).to.be.rejectedWith(methodErrorRegex);
});

it('should allow FormData as body', () => {
Expand Down Expand Up @@ -172,6 +176,7 @@ describes.sandboxed('fetch', {}, env => {

describe('Response', () => {
const TEST_TEXT = 'this is some test text';
const bodyUsedErrorRegex = /Body already used/;

it('should keep default status as 200 OK', () => {
const response = new Response(TEST_TEXT);
Expand Down Expand Up @@ -233,12 +238,13 @@ describes.sandboxed('fetch', {}, env => {
});

it('should provide text only once', () => {
expectAsyncConsoleError(bodyUsedErrorRegex);
const response = new Response(TEST_TEXT);
return response.text().then(result => {
expect(result).to.equal(TEST_TEXT);
expect(response.text.bind(response), 'should throw').to.throw(
Error,
/Body already used/
bodyUsedErrorRegex
);
});
});
Expand All @@ -264,11 +270,12 @@ describes.sandboxed('fetch', {}, env => {
});

it('should not be cloneable if body is already accessed', () => {
expectAsyncConsoleError(bodyUsedErrorRegex);
const response = new Response(TEST_TEXT);
return response.text().then(() => {
expect(() => response.clone(), 'should throw').to.throw(
Error,
/Body already used/
bodyUsedErrorRegex
);
});
});
Expand Down

0 comments on commit 601dd72

Please sign in to comment.