Skip to content

Commit

Permalink
support FakeXMLHttpRequest response property
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelly Selden committed Nov 7, 2019
1 parent e55af9c commit a0d00cc
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"typescript-eslint-parser": "^21.0.2"
},
"dependencies": {
"fake-xml-http-request": "^2.0.0",
"fake-xml-http-request": "kellyselden/FakeXMLHttpRequest#response",
"route-recognizer": "^0.3.3",
"whatwg-fetch": "^3.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function interceptor(ctx) {
var uploadEvents = [];

// properties to copy from the native xhr to fake xhr
var lifecycleProps = ['readyState', 'responseText', 'responseXML', 'responseURL', 'status', 'statusText'];
var lifecycleProps = ['readyState', 'responseText', 'response', 'responseXML', 'responseURL', 'status', 'statusText'];

var xhr = fakeXHR._passthroughRequest = new ctx.pretender._nativeXMLHttpRequest();
xhr.open(fakeXHR.method, fakeXHR.url, fakeXHR.async, fakeXHR.username, fakeXHR.password);
Expand Down
2 changes: 2 additions & 0 deletions test/calling_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe('pretender invoking', function(config) {
assert.equal(verb, 'GET');
assert.equal(path, '/some/path');
assert.equal(request.responseText, json);
assert.equal(request.response, json);
assert.equal(request.status, '200');
done();
};
Expand Down Expand Up @@ -625,6 +626,7 @@ describe('pretender invoking', function(config) {
assert.equal(verb, 'GET');
assert.equal(path, '/some/path');
assert.equal(request.responseText, json);
assert.equal(request.response, json);
assert.equal(request.status, '200');
done();
};
Expand Down
6 changes: 6 additions & 0 deletions test/passthrough_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ describe('passthrough requests', function(config) {
this.open = function() {};
this.setRequestHeader = function() {};
this.responseText = '';
this.response = '';
this.onload = true;
this.send = {
pretender: pretender,
Expand All @@ -328,6 +329,11 @@ describe('passthrough requests', function(config) {
event.target.responseText,
'responseText for real and fake xhr are both blank strings'
);
assert.equal(
xhr.response,
event.target.response,
'response for real and fake xhr are both blank strings'
);
done();
});

Expand Down
7 changes: 3 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1483,10 +1483,9 @@ extsprintf@^1.2.0:
resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.4.0.tgz#e2689f8f356fad62cca65a3a91c5df5f9551692f"
integrity sha1-4mifjzVvrWLMplo6kcXfX5VRaS8=

fake-xml-http-request@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.0.0.tgz#41a92f0ca539477700cb1dafd2df251d55dac8ff"
integrity sha512-UjNnynb6eLAB0lyh2PlTEkjRJORnNsVF1hbzU+PQv89/cyBV9GDRCy7JAcLQgeCLYT+3kaumWWZKEJvbaK74eQ==
fake-xml-http-request@kellyselden/FakeXMLHttpRequest#response:
version "2.0.1"
resolved "https://codeload.github.com/kellyselden/FakeXMLHttpRequest/tar.gz/a61474cc8cca4009f24f30fe42b3f6ba7ee4609e"

fast-deep-equal@^2.0.1:
version "2.0.1"
Expand Down

0 comments on commit a0d00cc

Please sign in to comment.