"Undefined is not a function" at .toBe fucntion

- 1 answer

Ad

I am writing a test to automate a scenario, using PROTRACTOR:

I am getting "Undefined is not a function" at .toBe below is my code: trying to get offset position of an element :

this.Then(/^I should have ONLY LOGO available on main page$/, function () { 
    element(by.id('mainPage')).getLocation().then(function (navDivLocation) { 
        var currTop = navDivLocation.y; 
        var currLeft = navDivLocation.x; 

        expect(currLeft).toBe(0); 
        expect(currTop).toBe(0); 
     }); 
});
Ad

Answer

Ad

Cucumber and Jasmine are mutually exclusive.

If you are not already, you should use Chai assertion library:

expect(currLeft).to.equal(0); 
expect(currTop).to.equal(0); 

To assert promises returned by different Protractor functions, use Chai-as-promised library - you would be able to pass promises inside the expect(). Example:

expect(elm.getText()).should.eventually.equal("my text");
Ad
source: stackoverflow.com
Ad