3

我正在尝试为类似于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>

问题是我的规范类总是在我的 app-test.js 文件中的 Ext.onReady 函数之前执行......所以例如我的 MR.view 没有定义。

请帮忙。

4

1 回答 1

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");
    });
于 2013-09-27T09:20:43.813 回答