Extending test class example

Get help with testing, discuss unit testing strategies etc.
Post Reply
User avatar
bjones
Premium Member
Premium Member
Posts: 6
Joined: Thu Nov 01, 2018 8:22 pm

Extending test class example

Post by bjones » Thu Nov 01, 2018 8:45 pm

I'm having trouble reproducing the extending test class example (https://www.bryntum.com/docs/siesta/#!/ ... test_class) using Siesta 5.1.1. When I execute my test case that uses the isOdd function, Test throws an exception: "TypeError: this.pass is not a function". The commented code for the setup override works when it is uncommented, so I'm not sure why the isOdd method is not working. If there is any other info you need, just let me know.

Code: Select all

Class('MyProject.MyTestClass', {
    isa     : Siesta.Test.Browser,

    // override: {
    //     setup   : function(callback, errback) {
    //         this.SUPER(function () {
    //             console.log('setup code reached');
                
    //             callback();
    //         }, errback)
    //     }
    // },

    methods : {
        isOdd : (number, description) => {
            if (number % 2) {
                this.pass(description);
            } else {
                this.fail(description, {
                    assertionName   : 'isOdd',
                    got             : number,
                    annotation      : 'Need odd number'
                });
            }
        }
    }
});

User avatar
nickolay
Core Developer
Core Developer
Posts: 3355
Joined: Mon May 16, 2011 10:48 am

Re: Extending test class example

Post by nickolay » Fri Nov 02, 2018 8:26 am

Oh, its because of the arrow function usage in global context. Arrow functions keep the scope of its declaration, in this case its a global object (window), so "this.pass()" becomes "window.pass()". Need to use regular functions for methods.
We offer training in both Ext JS and our products, read more here.
Read the API documentation

Post Reply