尝试使用 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();
});
});
});
现在显然这里有两种情况。浏览器和无头,因为这是执行之间的唯一差异。我会很感激任何想法。