我正在尝试为类似于Sencha Docs的控制器设置一些单元测试。
我还尝试在我的spec类之上定义我的View和我的Controller:
describe("User Administration Testing", function () {
var view = new MR.view.administration.User({ renderTo: Ext.getBody() }),
ctrl = new MR.controller.administration.User();
我在Ext.onReady(...)处理程序中的app-test.js中创建了这样的应用程序,如下所示:
Ext.onReady(function () {
Application = Ext.application({
name: 'MR',
extend: 'MR.Application',
autoCreateViewport: true,
launch: function () {
this.callParent();
//include the tests in the test.html head
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
}
});
});
我的run-tests.html看起来像这样:
<html>
<head>
<title id="page-title">Tester</title>
<link rel="stylesheet" type="text/css" href="app-test/lib/jasmine-1.3.1/jasmine.css">
<script type="text/javascript" src="ext/ext-debug.js"></script>
<script src="bootstrap.js"></script>
...
<!-- test launcher -->
<script type="text/javascript" src="app-test.js"></script>
<script type="text/javascript" src="app-test/lib/jasmine-1.3.1/jasmine.js"></script>
<script type="text/javascript" src="app-test/lib/jasmine-1.3.1/jasmine-html.js"></script>
<!-- include specs here -->
<script type="text/javascript" src="app-test/specs/GlobalSpec.js"></script>
<script type="text/javascript" src="app-test/specs/Administration/UserSpec.js"></script>
</head>
<body>
</body>
</html>
问题是我的spec类总是在我的app-test.js文件中的Ext.onReady函数之前执行...等等我的MR.view没有定义。
请帮忙。
答案 0 :(得分:1)
describe("User Administration Testing", function () {
var view = null, ctrl = null;
beforeEach(function () {
if(!view) view = Application.getView("User");
if(!ctrl) ctrl = Application.getController("User");
});