Skip to content

Commit

Permalink
Adds CORS support (XDomainRequest) for IE7+ still through XMLHttpRequest
Browse files Browse the repository at this point in the history
Details in developit#106
  • Loading branch information
3F committed Jan 8, 2019
1 parent 1670b30 commit 7d18541
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/index.mjs
Expand Up @@ -11,8 +11,10 @@ export default function(url, options) {

request.withCredentials = options.credentials=='include';

request.onload = () => {
resolve(response());
request.onreadystatechange = function() {
if(this.readyState === 4 && this.status === 200) {
resolve(response());
}
};

request.onerror = reject;
Expand Down
7 changes: 4 additions & 3 deletions test/index.js
Expand Up @@ -20,6 +20,7 @@ describe('unfetch', () => {
getAllResponseHeaders: jest.fn().mockReturnValue('X-Foo: bar\nX-Foo:baz'),
open: jest.fn(),
send: jest.fn(),
readyState: 4,
status: 200,
statusText: 'OK',
responseText: '{"a":"b"}',
Expand Down Expand Up @@ -60,10 +61,10 @@ describe('unfetch', () => {
expect(xhr.send).toHaveBeenCalledWith(null);
});

expect(xhr.onload).toEqual(expect.any(Function));
expect(xhr.onreadystatechange).toEqual(expect.any(Function));
expect(xhr.onerror).toEqual(expect.any(Function));

xhr.onload();
xhr.onreadystatechange();

return p;
});
Expand All @@ -76,7 +77,7 @@ describe('unfetch', () => {
expect(r.headers.get('X-foo')).toEqual('baz');
});

xhr.onload();
xhr.onreadystatechange();

return p;
});
Expand Down

0 comments on commit 7d18541

Please sign in to comment.