Throw an error if response() is called more than once on requests
Closes #71 Fixes #70
This commit is contained in:
parent
199324e720
commit
9908439d81
@ -249,6 +249,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
responseText: null,
|
||||
|
||||
response: function(response) {
|
||||
if (this.readyState === 4) {
|
||||
throw new Error("FakeXMLHttpRequest already completed");
|
||||
}
|
||||
this.status = response.status;
|
||||
this.statusText = response.statusText || "";
|
||||
this.responseText = response.responseText || "";
|
||||
@ -261,6 +264,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
},
|
||||
|
||||
responseTimeout: function() {
|
||||
if (this.readyState === 4) {
|
||||
throw new Error("FakeXMLHttpRequest already completed");
|
||||
}
|
||||
this.readyState = 4;
|
||||
jasmine.clock().tick(30000);
|
||||
this.onreadystatechange('timeout');
|
||||
|
@ -81,6 +81,22 @@ describe("FakeXMLHttpRequest", function() {
|
||||
expect(xhr.readyState).toEqual(4);
|
||||
expect(xhr.onreadystatechange).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when a second response comes in", function() {
|
||||
it("should throw an error", function() {
|
||||
xhr.onreadystatechange.calls.reset();
|
||||
xhr.response({status: 200});
|
||||
expect(function() { xhr.response({status: 200}); }).toThrowError('FakeXMLHttpRequest already completed');
|
||||
});
|
||||
});
|
||||
|
||||
describe("when a second response comes in as a timout", function() {
|
||||
it("should throw an error", function() {
|
||||
xhr.onreadystatechange.calls.reset();
|
||||
xhr.response({status: 200});
|
||||
expect(function() { xhr.responseTimeout(); }).toThrowError('FakeXMLHttpRequest already completed');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when aborted", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user