Categories
JavaScript Answers

How to make a test fail with Jest and JavaScript?

Spread the love

Sometimes, we want to make a test fail with Jest and JavaScript.

In this article, we’ll look at how to make a test fail with Jest and JavaScript.

How to make a test fail with Jest and JavaScript?

To make a test fail with Jest and JavaScript, we can throw an error in our test.

For instance, we write

test("test", () => {
  throw new Error("I have failed you");
});

to throw an Error object in our test callback to make the test fail.

Conclusion

To make a test fail with Jest and JavaScript, we can throw an error in our test.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *