waitsFor
ジャスミンのテストを開始する前に、すべてのリモート ファイルがロードされるまで待ちたいと思います (specfile のどこでも,を処理したくないため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(...)
....
})