You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
952 B
39 lines
952 B
10 years ago
|
var chai = require('chai');
|
||
|
var assert = chai.assert;
|
||
|
|
||
|
var FakeXMLHttpRequest = function () {
|
||
|
this.responseText = "{}";
|
||
|
this.readyState = 4;
|
||
|
this.onreadystatechange = null;
|
||
|
this.async = false;
|
||
10 years ago
|
this.headers = {
|
||
|
'Content-Type': 'text/plain'
|
||
|
};
|
||
10 years ago
|
};
|
||
|
|
||
|
FakeXMLHttpRequest.prototype.open = function (method, host, async) {
|
||
|
assert.equal(method, 'POST');
|
||
|
assert.notEqual(host, null);
|
||
|
assert.equal(async === false || async === true, true);
|
||
|
this.async = async;
|
||
|
};
|
||
|
|
||
10 years ago
|
FakeXMLHttpRequest.prototype.setRequestHeader = function(name, value) {
|
||
|
this.headers[name] = value;
|
||
|
};
|
||
|
|
||
10 years ago
|
FakeXMLHttpRequest.prototype.send = function (payload) {
|
||
|
assert.equal(typeof payload, 'string');
|
||
|
if (this.async) {
|
||
|
assert.equal(typeof this.onreadystatechange, 'function');
|
||
|
this.onreadystatechange();
|
||
|
return;
|
||
|
}
|
||
|
return this.responseText;
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
XMLHttpRequest: FakeXMLHttpRequest
|
||
|
};
|
||
|
|