Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasmine 2 custom matcher for hasClass in Protactor

I upgrade my Jasmine 1.3 to 2.0 so I added a custom matcher to check css is present.Below is the code to check the matcher

hasClass = function(actual,expected){
    return actual.getAttribute('class').then(function (classes) {
            return classes.split(' ').indexOf(expected) !== -1;
        });
}   

But when I upgrade to Jasmine 2 then promise throws error by protactor as it expect return but below is async process

hasClass = function(){
     return compare: function(actual,expected){
        return actual.getAttribute('class').then(function (classes) {
                return {pass: classes.split(' ').indexOf(expected) !== -1};
            });
    }
}

How can I test class is present in element I don't want to use jasmine-jquery??

like image 795
Arpit Avatar asked May 25 '15 15:05

Arpit


1 Answers

The pass should be a promise, not resolved in one. Try to place this in your beforeEach:

this.addMatchers({
    hasClass: function() {
        return {
            compare: function(actual, expected) {
                return {
                    pass: actual.getAttribute('class').then(function(classes) {
                        return classes.split(' ').indexOf(expected) !== -1;
                    })
                };
            }
        };
    }
});
like image 118
Delian Mitankin Avatar answered Oct 03 '22 04:10

Delian Mitankin