'What are assertions in JEST?
It's documentation says that while dealing with async code, expect.assertions(x)
should be written.
What exactly do assertions refer to? Is it a term of plain JavaScript?
Solution 1:[1]
In this context, it's testing terminology, it doesn't have a special meaning.
With expect.assertions(n)
, you're telling Jest that you expect the current test to perform n
assertions. An assertion is a check that values meet certain conditions.
In other words, if you use expect.assertions(5)
the test will fail unless expect()
is called at least 5 times.
This is useful for async tests, but it's not the only way to handle asynchronicity, you can find other patterns in the Jest doc.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | roperzh |