我正在尝试完成Jasmine测试(使用Karma和IntelliJ 13)来验证JSON文件.理想情况下,我的测试只是将JSON文件加载到数据对象中,然后让我解析以检查有效的格式和数据.我不需要在之前或之后验证函数,也不需要针对服务器进行测试.
我的基本设置是这样的:
it("should load an external file", function(){
var asyncCallComplete, result,
_this = this;
// asyncCallComplete is set to true when the ajax call is complete
asyncCallComplete = false;
// result stores the result of the successful ajax call
result = null;
// SECTION 1 - call asynchronous function
runs(function() {
return $.ajax('/test/config.json', {
type: 'GET',
success: function(data) {
asyncCallComplete = true;
result = data;
},
error: function() {
asyncCallComplete = true;
}
});
});
// SECTION 2 - …Run Code Online (Sandbox Code Playgroud)