can-fixture
Advanced tools
Comparing version 0.3.1 to 0.3.2
{ | ||
"name": "can-fixture", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"description": "Intercept AJAX requests and simulate responses.", | ||
@@ -5,0 +5,0 @@ "main": "fixture.js", |
@@ -1350,1 +1350,26 @@ var Qunit = require('steal-qunit'); | ||
}); | ||
asyncTest('responseText & responseXML should not be set for arraybuffer types (#38)', function() { | ||
fixture('/onload', '/test/fixtures/foo.json'); | ||
var oldError = window.onerror; | ||
window.onerror = function (msg, url, line) { | ||
ok(false, 'There should not be an error'); | ||
start(); | ||
} | ||
var xhr = new XMLHttpRequest(); | ||
xhr.addEventListener('load', function() { | ||
fixture('/onload', null); | ||
window.onerror = oldError; | ||
ok(true, 'Got here without an error'); | ||
start(); | ||
}); | ||
xhr.responseType = 'arraybuffer'; | ||
xhr.open('GET', '/onload'); | ||
xhr.send(); | ||
}); |
12
xhr.js
@@ -67,2 +67,11 @@ // This overwrites the default XHR with a mock XHR object. | ||
xhr.onreadystatechange = function(ev){ | ||
// If the XHRs responseType is not '' or 'text', browsers will throw an error | ||
// when trying to access the `responseText` property so we have to ignore it | ||
if(xhr.responseType === '' || xhr.responseType === 'text') { | ||
delete propsToIgnore.responseText; | ||
delete propsToIgnore.responseXML; | ||
} else { | ||
propsToIgnore.responseText = true; | ||
propsToIgnore.responseXML = true; | ||
} | ||
@@ -72,3 +81,4 @@ // Copy back everything over because in IE8 defineProperty | ||
// values as the real xhr. | ||
assign(mockXHR, xhr,propsToIgnore); | ||
assign(mockXHR, xhr, propsToIgnore); | ||
if(mockXHR.onreadystatechange) { | ||
@@ -75,0 +85,0 @@ mockXHR.onreadystatechange(ev); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
90880
2288