Get help with testing, discuss unit testing strategies etc.


Post by bjones »

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.
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'
                });
            }
        }
    }
});

Post by nickolay »

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.

Post Reply