【问题标题】:Chutzpah Test Adapter issue using ExtJS - Works in browser. Not in IDE使用 ExtJS 的 Chutzpah 测试适配器问题 - 在浏览器中工作。不在IDE中
【发布时间】:2013-05-25 19:41:12
【问题描述】:

尝试使用 Chutzpah 和 Jasmine 对 ExtJS 应用程序进行单元测试。在 VS 2012 中检测到测试并显示在测试资源管理器中。附加的示例在浏览器中运行时通过。但是,在 IDE 中运行它,我的商店测试失败了。现在 Ext 创建了一个单例应用程序对象 (v 4.1.3) 并创建了一个 Chutzpah 可以看到的应用程序特定的命名空间,但是一旦我尝试从命名空间加载控制器,AppName.app.getController('My.controller.Controller ') 没有说它未定义。

app_jasmine.js

Ext.Loader.setConfig({ enabled: true }); 
Ext.require('Ext.app.Application');

Ext.ns('My');

My.app = this;

Ext.application({
    name: 'My',
    controllers: ['My'],
    init: function () {
        My.app = this;
    },
    launch: function () {
        jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
        jasmine.getEnv().execute();
    }
});

SpecRunner.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="css/jasmine.css" rel="stylesheet" />

    <script type="text/javascript" src="http://cdn.sencha.io/ext-4.1.1-gpl/ext-all-debug.js"></script>

    <script type="text/javascript" src="Scripts/jasmine.js"></script>
    <script type="text/javascript" src="Scripts/jasmine-html.js"></script>

    <!-- include specs here -->
    <script type="text/javascript" src="tests/specs/MySpecs.spec.js"></script>

    <!-- test launcher -->
    <script type="text/javascript" src="tests/app_jasmine.js"></script>

</head>
<body>

</body>
</html>

MySpecs.specs.js

/// <reference path="http://cdn.sencha.io/ext-4.1.1-gpl/ext-all-debug.js" />
/// <reference path="../../Scripts/jasmine.js" />
/// <reference path="../app_jasmine.js" />
describe("Store", function () {
    var store = null,
        ctlr = null;

    beforeEach(function () {
        if (!ctlr) {        
            ctlr = My.app.getController('My');
        }

        if (!store) {
            store = ctlr.getStore('My');
        }

        expect(store).toBeTruthy();

        waitsFor(
            function () { return !store.isLoading(); },
            "load never completed",
            4000
        );
    });

    it("should have records", function () {
        expect(store.getCount()).toBeGreaterThan(1);
    });

});

describe(" Application Test ", function () {
    describe(" Assumptions ", function () {   
        it(" has loaded ExtJS4 library.", function () {
            expect(Ext).toBeDefined();
            expect(Ext.getVersion()).toBeTruthy();
            expect(Ext.getVersion().major).toEqual(4);
        });

        it(" has loaded application.", function () {
            expect(My).toBeDefined();
        });
    });
});

现在显然这里有两个上下文。浏览器和无头,因为这是执行之间的唯一差异。我会很感激任何想法。

【问题讨论】:

    标签: extjs jasmine chutzpah


    【解决方案1】:

    您是否尝试过引用 ext-all-debug.js 的本地副本?

    也许 Chutzpah/PhantomJS 无法访问 sencha CDN,因此没有加载 ExtJS。

    P.S.:我建议您使用 Chutzpah 特定参考:

    /// <chutzpah_reference path="../../Scripts/jasmine.js" />
    

    而不是

    /// <reference path="../../Scripts/jasmine.js" />
    

    为了避免与同样使用 reference 命令的其他库可能发生冲突。更多详情here.

    【讨论】:

    • 我没想过让图书馆成为本地图书馆。我按照您的建议尝试了,但没有效果。 QUnit 是一个完全不同的野兽,Chutzpha 根本看不到测试。
    猜你喜欢
    • 2013-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多