'Does chai assertion library return true/false on passed/failed step?

I am using webdriverio with chai assertion library for UItesting, while asserting a string i was wondering if I can make chai to return true/false when the assert passed or failed depending on the step.

var text = "some test";
var result = assert(text === "some test");
console.log(result);

The output from the above code is undefined

Is there a way I can make it return true or false? or is there another library that I could use which supports this action.

Thanks



Solution 1:[1]

Here is a same question as yours and the last answer is clarify some part of your issue. But for a work around suggestion, you can write your custom assert methods using chai assert. If chai assertion will fail, your assert method will return false and if it will pass you will return true.

Solution 2:[2]

According to the explanation provided by Chai developers (thanks for the Github link slckayhn), assertions do not return a boolean in order for the chain to be continued, but an error is thrown. Therefore, simply use a try+catch:

try {
  assert(text === "some test", "Assert log message");
  cy.log("Assertion yielded true");
} catch (error) { // `error` contains "Assert log message" 
  cy.log("Assertion yielded false");
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 slckayhn
Solution 2 CPHPython