B
B
beem72021-05-08 10:56:15
Software testing
beem7, 2021-05-08 10:56:15

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

1 answer(s)
A
Alexey Ukolov, 2021-05-11
@beem7

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 question

Ask a Question

731 491 924 answers to any question