Get help with testing, discuss unit testing strategies etc.


Post by brownmonk »

I'm trying to write a test that clicks the login button on a window/form. I'm also testing that the global variables are being set to figure out what is going on here.

The test below for workingUserId passes if the window.show call comes after I defined all my globals (Window.show at Point B in my launch function below)

If I move it to Point A, then the test fails.

I'm guessing that show is pausing execution or something? Under no circumstances can I get a reference to my window (I tried a lot of different ways)
All of those ways give me a good reference from inside my launch function, just not in my test.

Any insight into what is going on here?


Here's my test:
StartTest(function(t) {

    t.beginAsync(); // trying things, this didn't help. What's an 'asynchronous frame' ?

    t.is(MyApp.globals.workingUserId, "C164B8E2-3751-44DA-A38B-A02E00A8E679".toLowerCase(), 'Ids equal'); // works if W.show is at Point B, fails if it is at Point A (see launch function below)
    var login = Ext.getCmp('loginwindow');  // never gives me a reference in the test. Works if I put same code in the launch function.
    t.ok(login, 'login ok');

    t.endAsync();
    /* Other things I tried.
    var login = Ext.getCmp('loginwindow');
    var body = Ext.getBody().down('#btnLogin');
    var usernameField = Ext.select('txtUid').first();
    console.dir(usernameField);
    t.ok(usernameField);
    console.dir(login);
    console.dir(MyApp);
    */
});
Here's my application launch function:
launch: function () {
        console.log('Entering application launch!');

        //Point A
        Ext.create('MyApp.desktop.view.login.LoginWindow').show();


        Ext.Ajax.cors = true;
        Ext.Ajax.useDefaultXhrHeader = false;
        MyApp.globals = {};
        MyApp.globals.workingUserId = "C164B8E2-3751-44DA-A38B-A02E00A8E679".toLowerCase();
        MyApp.globals.eventBroadcaster = Ext.create('MyApp.desktop.event.EventBroadcaster');
        MyApp.globals.eventBroadcaster.addListener('testEvent', function () { console.log('fired event testEvent'); }, this);

        // Point B  
        //Ext.create('MyApp.desktop.view.login.LoginWindow').show();

        MyApp.app = this;
        console.log('Leaving application launch!');
    }

Post by nickolay »

You probably need to wait until your application launch, before running the test. Starting from 1.0.8, there's a special option for that - `waitForAppReady`: https://bryntum.com/products/siesta/docs ... orAppReady

You can also do it manually, using "waitFor":
StartTest(function (t) {
    
    t.waitFor(function () {
        return typeof SomeMyGlobal != 'undefined'
    }, function () {
        
        // the rest of test here
    })
    
})

Post by brownmonk »

That works, thanks!

Post Reply