1

I was trying to check whether a string is present in another string. I am using the below code:

expect(actualTimeZone).to.include(employee.timeZone);

But it is giving the below error:

AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but object given

But when I tried with the below code, it is not throwing the above error:

expect(actualTimeZone).to.eventually.equal(employee.timeZone);

I am working on protractor framework with cucumber and javascript. Could someone help to solve this issue.

0

You need to identify that the test shouldn't pass until the promise you're waiting on is resolved!

to.include() it does not resolve the promise

how to.include() is: Use the include matcher to specify that a collection includes one or more expected objects. It succeeds if any object of the given collection passes the specified matcher. This works on any object that responds to #include? (such as a string or array):

and the reason it passes with to.eventually.include() is it deals with promise

Promised is the eventually property. With it, you can transform any existing Chai assertion into one that acts on a promise:

if you want to.include() work why dont you simply do this may work.

    const arr = [actualTimeZone];
    expect(arr).to.include(employee.timeZone);

note : this solution is based on how your error suggest.

with this you need to resolve promise

it('xyz', (done) => {
  element(by.selector(element).getText())
  .then(t => {
     expect(t).then(a => to.include(y);
     done();
  });
});
  • Thanks for your reply. But that change doesn't make any difference to the error.And also the other one I mentioned was to.eventually.equal , not to.eventually.include – RRR Dec 20 '18 at 11:46
  • okay i forget to mention that either you return an array and resolve it with async/await – Rao Dec 20 '18 at 11:50
  • i updated answer and refer this – Rao Dec 20 '18 at 11:55
0

I tried using the below code and it is working

expect(actualTimeZone).to.eventually.include(employee.timeZone);

  • this is because it resolves the promise – Rao Dec 20 '18 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.