我正在使用jasmine 来测试 JavaScript 代码。
javascript 代码由使用 requireJs 加载的模块组成。 当我使用需要的 json requirejs-plugins
加载 json 文件时,我在 Web 浏览器上看不到任何输出。
奇怪的是我也没有收到任何 javascript 错误。text! plugin
这是我的代码(1)。
有任何想法吗?
PS:
不确定,但问题可能与时间延迟有关。
如果我从本地 ( time latency = 6ms
) 获取文件,它就可以工作。
如果我从远程服务器 ( ) 获取文件(具有相同的本地内容),time latency = 170 ms
它将显示一个空页面。
知道如何解决这个问题吗?
(1)
/*global define, window*/
(function () {
'use strict';
var specUrl = './';
define([
'jasmine',
'jasmineHtml',
'jasmineJquery',
'json!json_data', // if I comment this line is ok,
// otherwise I get empty page with no error
specUrl + 'models/user.spec'
], function (jasmine) {
var initialize = function () {
// some code
};
return {
initialize: initialize
};
});
}());
我确实阅读了有关异步规范的文档,但尚不清楚如何解决该问题。有任何想法吗?
我确实发布了一个非常简单的代码:(1)有效,(2)无效,因为从服务器获取 json_data 可能需要大约 250 毫秒。
(1)
define([
'appJasmine',
// 'json!json_data',
], function (app) {
app.initialize(); // it display data on browser
});
(2)
define([
'appJasmine',
'json!json_data',
], function (app) {
app.initialize(); // it does not display data on browser
});