在我开始测试我的茉莉花之前,我想等到所有远程文件都加载完毕(因为我不想处理我的规范文件waitsFor
中spyes
的任何地方,但只在文件的开头)
loadDoc
是我创建的用于加载远程文件的函数
loadDoc = function(path, callBack, noDocx) {
var xhrDoc;
if (noDocx == null) {
noDocx = false;
}
xhrDoc = new XMLHttpRequest();
docxCallback[path] = callBack;
xhrDoc.open('GET', "../examples/" + path, true);
if (xhrDoc.overrideMimeType) {
xhrDoc.overrideMimeType('text/plain; charset=x-user-defined');
}
xhrDoc.onreadystatechange = function(e) {
if (this.readyState === 4 && this.status === 200) {
window.docXData[path] = this.response;
if (noDocx === false) {
window.docX[path] = new DocxGen(this.response);
}
return docxCallback[path]();
}
};
return xhrDoc.send();
};
测试:
describe("DocxGen", function() {
var globalcallBack;
globalcallBack = jasmine.createSpy();
loadDoc('imageExample.docx', globalcallBack);
loadDoc('image.png', globalcallBack, true);
....
waitsFor(function() {
return globalcallBack.callCount >= 10;
});
describe(...)
....
})