lundi 23 novembre 2015

Sencha Touch [APPNAME].app is undefined only when testing with Jasmine

I'm trying to set up some test cases for a view using the Jasmine 2.3.4 assertion library for my Sencha Touch 2.4 app. Things seem great (I see the view rendered to a div) except the browser does not know what MyApp.app is. I have this line at my onContainerInitialize function from my view/container code:

var controller = MyApp.app.getController('loginController');

which gives this Jasmine error:

TypeError: Cannot read property 'getController' of undefined

At the time the Jasmine tests are called, from my console I do have a MyApp global object with the following structure (attached). If you expand app you will see the class name of the controller listed in an array under _controllers. The line that causes this error in my spec file is:

var myView = new MyApp.view.someViewName({ renderTo: 'test' });

I modeled my setup after a few tutorials, one of which is Sencha's http://ift.tt/1IbAPOY (wish there was one for a recent version of Touch). I think my problem may be related to this note midway down that page:

Note: this Application definition is not a copy and paste of your regular Application definition in your app.js. This version will only include the controllers, stores, models, etc and when launch is called it will invoke the Jasmine tests.

It may be related, but I also couldn't follow their:

ctrl = newMyApp.controller.MyController();

where I would get this error:

TypeError: app.getRouter is not a function at Ext.define.applyRoutes (http://localhost:8080/touch/sencha-t...ug.js:45800:26)

Instead, I had to add in this argument like this:

var ctrl = new Kaacoo.controller.loginController({ application : app });

Additionally, my launch file is set up like this:

Ext.require('Ext.app.Application');

Ext.Loader.setConfig({
    enabled: true,
    disableCaching: true
});

Ext.Loader.setPath('MyApp', '../../app');
// this file is a couple levels deep from the root of my project

Ext.application({
    name : 'MyApp',
    extend: 'MyApp.Application',
    autoCreateViewport: true,
    controllers: [
        'loginController'
    ],

    requires : [
    ],

    launch: function() {
        // Jasmine is bootstrapped with boot.js referenced in the html runner, so nothing here. My test specs are being called after this launch function is executed. 
    }
});

The order I have listed my resources in my html runner are: Jasmine Library with boot.js> Touch All Debug Library > Project Source Files > Spec Files > Launch file

Building and simulating the app is fine, so why can't I also have access to MyApp.app.getController('loginController') as well in my test environment?

Thanks!

Aucun commentaire:

Enregistrer un commentaire