Answer the question
In order to leave comments, you need to log in
Is it good practice in unit tests to always use === instead of ==?
Benefit:
- Protects against cases like: "code returns false instead of empty string, test doesn't see the difference because == is the same thing, but caller doesn't need bool instead of string".
And if you use strictEqual everywhere , then there will be no risk of forgetting and allowing the usual equal somewhere.
Disadvantage:
- if you use it everywhere , it visually clogs the test code. assert.strictEqual is longer than assert.equal and so is deepStrictEqual. At the same time, in 90% of checks it is not needed.
And if it is so necessary, then why didn't they make a short version in all assertion libraries to make it less cluttered, or didn't they do exactly === in all assert.equal at all?
Answer the question
In order to leave comments, you need to log in
Is an.
Doesn't clog.
"Why didn't they do it" - ask the authors of all sorts of laybrar'ies.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question