10

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?

1 Answer 1

12

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.