尝试使用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();
});
});
});
现在显然这里有两种情况。浏览器和无头,因为这是执行之间唯一的差异。我很感激任何想法。
答案 0 :(得分:0)
您是否尝试过引用ext-all-debug.js的本地副本?
也许Chutzpah / PhantomJS无法访问sencha CDN,因此没有加载ExtJS。
P.S。:我建议您使用Chutzpah特定参考:
/// <chutzpah_reference path="../../Scripts/jasmine.js" />
而不是
/// <reference path="../../Scripts/jasmine.js" />
避免与也使用引用命令的其他库发生冲突。更多详情here。