Question

Trying to use Chutzpah with Jasmine to unit test an ExtJS application. Tests are detected and appear in the test explorer in VS 2012. The attached sample passes when running in the browser. However, running it the IDE, my store test fails. Now Ext creates a singleton application object (v 4.1.3) and am creating an application specific namespace that Chutzpah can see but as soon as I attempt to load a controller from the namespace, AppName.app.getController('My.controller.Controller') fails saying its undefined.

app_jasmine.js

Ext.Loader.setConfig({ enabled: true }); 
Ext.require('Ext.app.Application');

Ext.ns('My');

My.app = this;

Ext.application({
    name: 'My',
    controllers: ['My'],
    init: function () {
        My.app = this;
    },
    launch: function () {
        jasmine.getEnv().addReporter(new jasmine.HtmlReporter());
        jasmine.getEnv().execute();
    }
});

SpecRunner.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="css/jasmine.css" rel="stylesheet" />

    <script type="text/javascript" src="http://cdn.sencha.io/ext-4.1.1-gpl/ext-all-debug.js"></script>

    <script type="text/javascript" src="Scripts/jasmine.js"></script>
    <script type="text/javascript" src="Scripts/jasmine-html.js"></script>

    <!-- include specs here -->
    <script type="text/javascript" src="tests/specs/MySpecs.spec.js"></script>

    <!-- test launcher -->
    <script type="text/javascript" src="tests/app_jasmine.js"></script>

</head>
<body>

</body>
</html>

MySpecs.specs.js

/// <reference path="http://cdn.sencha.io/ext-4.1.1-gpl/ext-all-debug.js" />
/// <reference path="../../Scripts/jasmine.js" />
/// <reference path="../app_jasmine.js" />
describe("Store", function () {
    var store = null,
        ctlr = null;

    beforeEach(function () {
        if (!ctlr) {        
            ctlr = My.app.getController('My');
        }

        if (!store) {
            store = ctlr.getStore('My');
        }

        expect(store).toBeTruthy();

        waitsFor(
            function () { return !store.isLoading(); },
            "load never completed",
            4000
        );
    });

    it("should have records", function () {
        expect(store.getCount()).toBeGreaterThan(1);
    });

});

describe(" Application Test ", function () {
    describe(" Assumptions ", function () {   
        it(" has loaded ExtJS4 library.", function () {
            expect(Ext).toBeDefined();
            expect(Ext.getVersion()).toBeTruthy();
            expect(Ext.getVersion().major).toEqual(4);
        });

        it(" has loaded application.", function () {
            expect(My).toBeDefined();
        });
    });
});

Now obviously there are two contexts here. The browser and headless as this is the only variance between executions. I would appreciate any ideas.

Était-ce utile?

La solution

Have you tried referencing a local copy of ext-all-debug.js?

Perhaps Chutzpah/PhantomJS are failing to access the sencha CDN and therefore ExtJS is not being loaded.

P.S.: I'd suggest you to use Chutzpah specific reference:

/// <chutzpah_reference path="../../Scripts/jasmine.js" />

instead of

/// <reference path="../../Scripts/jasmine.js" />

To avoid possible conflicts with other libraries that also use the reference command. More details here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top