What is the difference between strictEqual() and equal() in chai?
The difference is that each one is related to the identity (
===) and equality(
==) operators respectively. If we remember, the
== operator will compare for equality after any necesary type conversions on the values, for example if we are checking for this equality:
2 == '2' ? true : false; which is the same as:
assert.equal(2, '2') .
There we will have a response of
true because the operator will check across types, turning either 2 into ‘2’(string) or ‘2’ into 2(number) which will lead them to become equal since the character stays the same.
assert.strictEqual(2, '2') and
2 === '2' ? true : false; will return false because the
=== operator do not do any conversions, it strictly checks if the value and the type are the same, if so, it would return true.