Check if element has class with Jasmine test environment only

I use webdriverJSand Jasmineto do end-to-end testing of a web page. I would like to check if the element has classunder certain circumstances, but I would like to do this using the methods from Clean Jasmine .

This is the part of the code where the problem is located:

describe('Header bar', function() {
    it('should show/hide elements accoding to the window position', function() {
        this.driver.executeScript('scroll(0, 1000)');
        var elemSearch = this.driver.findElements(webdriver.By.id('animatedElement, animatedElement2, animatedElement3'));
        expect(elemSearch).toContain('appear-2');
    });
})

Do you know if there is a way to solve this problem or a couple of examples that I could look at without using extensions such as jasmine-jquery?

Thanks in advance for your answers!

+1
source share
1 answer

, jasmine-jquery jasmine-matchers , toHaveClass() . , , , DRY .

FYI, toHaveClass, :

beforeEach(function() {
    jasmine.addMatchers({
        toHaveClass: function() {
            return {
                compare: function(actual, expected) {
                    return {
                        pass: actual.getAttribute("class").then(function(classes) {
                            return classes.split(" ").indexOf(expected) !== -1;
                        })
                    };
                }
            };
        },
    });
});
+2

All Articles