guy mograbi
guy mograbi

Reputation: 28608

How to return `false` with custom matcher in protractor/jasmine?

I am using protractor 3.0.0, and jasmine 1.3.1.

I am trying to add a custom matcher, but it seems that I can only use it if it returns true otherwise my test gets stuck.

This is my custom matcher

 toBecomeTrue: function(){
     return browser.sleep(0).then(function(){
         return false;
      });
 },

As you can see, I want the test to fail.

However, when I use it

it('should ask an SO question', function(){
    browser.get('/');
    expect($$('div')).toBecomeTrue();
});

The test gets stuck..

My instinct is that since we are dealing with promises, and since I am returning false.. something is going wrong..

So I am throwing an error instead.. but that does not allow me to use not. :(

However, I can't seem to find it documented anywhere, and I am feeling like I am doing something wrong.

Here are a couple of implementations examples I saw and tried but couldn't make it to work

Regarding jasmine version, why am I still looking at documentations for 1.3, I have a different question for that.. hope to resolve it soon.

so to recap:

Upvotes: 1

Views: 157

Answers (1)

Nick
Nick

Reputation: 504

Jamine 1.3 is not compatible with protractor version of 3.0.0, From GitHub:

We're releasing version 3.0 with some breaking changes. In summary - Jasmine 1.3 is removed, only Jasmine 2 is now supported, old Node.JS support is dropped, and plugins now need to be explicitly required. Full details below.

Upvotes: 1

Related Questions