在使用jasmine + karma + phantomjs + es6-promises(npm lib)进行测试时,发现了以下问题,但我找不到正在发生的事情。我想知道是否有人可以查看并帮助确定问题:
at formatError (/usr/local/lib/node_modules/gulp-cli/lib/versioned/^3.7.0/formatError.js:20:10)
at Gulp.<anonymous> (/usr/local/lib/node_modules/gulp-cli/lib/versioned/^3.7.0/log/events.js:41:15)
at emitOne (events.js:90:13)
at Gulp.emit (events.js:182:7)
at Gulp.Orchestrator._emitTaskDone (/Users/helder/www/coach-test/node_modules/orchestrator/index.js:264:8)
at /Users/helder/www/coach-test/node_modules/orchestrator/index.js:275:23
at finish (/Users/helder/www/coach-test/node_modules/orchestrator/lib/runTask.js:21:8)
at cb (/Users/helder/www/coach-test/node_modules/orchestrator/lib/runTask.js:29:3)
at removeAllListeners (/Users/helder/www/coach-test/node_modules/karma/lib/server.js:379:7)
at Server.<anonymous> (/Users/helder/www/coach-test/node_modules/karma/lib/server.js:390:9)
at Server.g (events.js:273:16)
at emitNone (events.js:85:20)
at Server.emit (events.js:179:7)
at emitCloseNT (net.js:1514:8)
at nextTickCallbackWith1Arg (node.js:464:9)
at process._tickCallback (node.js:386:17)
我有一个执行XHR请求的方法:
function List (params) {
this.init(params);
}
List.prototype = {
init: function (params) {
// ....
},
requestData: function (url) {
var promise = new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function (ev) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
console.log(xhr.responseText);
resolve(xhr.responseText);
} else {
reject(Error(xhr.statusText));
}
}
};
xhr.send(null);
});
return promise;
}
};
module.exports = List;
茉莉花测试规范:
describe("List generator", function () {
var request = null;
var list = new List({ autoload: false });
beforeEach(function (done) {
jasmine.Ajax.install();
list.requestData(config.api).then(function () {
done();
});
request = jasmine.Ajax.requests.mostRecent();
expect(request.url).toBe(config.api);
expect(request.method).toBe('GET');
});
});