小编Ale*_*exB的帖子

从Karma/Jasmine测试加载外部文件

我正在尝试完成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)

javascript json intellij-idea jasmine karma-runner

25
推荐指数
2
解决办法
3万
查看次数

标签 统计

intellij-idea ×1

jasmine ×1

javascript ×1

json ×1

karma-runner ×1