A
A
Alexander Kositsyn2018-01-31 00:58:01
JavaScript
Alexander Kositsyn, 2018-01-31 00:58:01

Why does the function in chai isBelow not want to accept a string?

There is a test in which you need to check if the string "test" > "rest" is allowed. To do this, chai assert has the isBelow function.
documentation
link to full documentation
says that it accepts mixed. means it must accept a string.
but when I insert a line it displays an error screen
that it was expected either a number or a date.
Maybe someone has come across this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Kitmanov, 2018-01-31
@alex_keysi

Mixed is some kind of wet fantasy of the authors of chai - this type is not in JS, not even in TS or Flow. If separately somewhere in the docks it is not indicated that Mixed is for example number | string, then it remains only to look at the source and try to understand from use what exactly was meant. Apparently, it meant “anything and different every time”, sooooo useful documentation :)
Judging by the code , only Data and number are accepted.
How not to suffer expect('test' > 'rest').to.be.true;:. It seems counter-intuitive, but in fact, such tests are easier to read and maintain.

A
Ainur Valiev, 2018-01-31
@vaajnur

strings are not checked that way. isBelow() is a number comparison, use
assert.equal('123', '4564', 'not equal')

A
Alexander, 2018-01-31
@SAnhPa

mixed means more than one type, in this case two - a number and a date.
Based on the documentation, isBelow checks for the condition "the first is less than the second". How are you going to compare strings?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question