Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ext.JS 4.2.1 UnitTesting using Jasmine - Application Not defined

I am trying to set up a some Unit Tests for a Controller similar to Sencha Docs.

I also try to define my View and my Controller on top of my spec class:

describe("User Administration Testing", function () {
    var view = new MR.view.administration.User({ renderTo: Ext.getBody() }),
        ctrl = new MR.controller.administration.User();

I create the Application in my app-test.js in Ext.onReady(...) handler like this:

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();
        }
    });

});

and my run-tests.html looks like this:

<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>

The problem is that my spec class executes always before my Ext.onReady function in my app-test.js file... and so e.g. my MR.view is not defined.

Please help.

like image 779
TheJoeIaut Avatar asked Dec 31 '25 04:12

TheJoeIaut


1 Answers

describe("User Administration Testing", function () {
    var view = null, ctrl = null;
    beforeEach(function () {
        if(!view) view = Application.getView("User");
        if(!ctrl) ctrl = Application.getController("User");
    });
like image 94
stan Avatar answered Jan 02 '26 18:01

stan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!