Chai uses re.exec when it tests a regular expression re. This regular expression matches '000' and its lastIndex is set to 3 (because the g flag is set). The next test calls re.exec('110'). The match starts from the new lastIndex position and it fails.
There is something weird indeed with the tests, if you only leave that one in the sample tests, your code passes it. But, your code is not ok, and it returns true for any combination of 0 and 1 with 3 digits.
The regular expression should not use the
g
flag.Chai uses
re.exec
when it tests a regular expressionre
. This regular expression matches'000'
and itslastIndex
is set to3
(because theg
flag is set). The next test callsre.exec('110')
. The match starts from the newlastIndex
position and it fails.There is something weird indeed with the tests, if you only leave that one in the sample tests, your code passes it. But, your code is not ok, and it returns true for any combination of 0 and 1 with 3 digits.
No, they are not identical: