Qunitjs | rejects function

The rejects() is a built-in function of Qunitjs test suite which test if the provided promise rejects, and optionally compare the rejection value.

When testing code that is expected to return a rejected promise based on a specific set of circumstances, use assert.rejects() for testing and comparison.

The expectedMatcher argument can be:

  • A function that returns true when the assertion should be considered passing.
  • An Error object
  • A base constructor to use ala rejectionValue instanceof expectedMatcher
  • A RegExp that matches (or partially matches) rejectionValue.toString()

Syntax:

rejects() function example

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Editorial Staff

Editorial Staff at FreeWebMentor is a team of professional developers.