Ext.JS 4.2.1使用Jasmine进行单元测试-未定义应用程序

Ext.JS 4.2.1 UnitTesting using Jasmine - Application Not defined

本文关键字:单元测试 未定义 应用程序 Jasmine JS 使用 Ext      更新时间:2023-09-26

我正在尝试为类似于Sencha Docs的控制器设置一些单元测试。

我还试图在我的规范类之上定义我的视图和控制器:

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没有被定义。

请帮忙。

describe("User Administration Testing", function () {
    var view = null, ctrl = null;
    beforeEach(function () {
        if(!view) view = Application.getView("User");
        if(!ctrl) ctrl = Application.getController("User");
    });