What is assertion methods?

79 views Asked by At

I'm learning AVAJS recently. One thing that sounds kind of abstract to me is 'assertion methods', or simply assertion. For example:

enter image description here

What is it, or what it actually does in programming. I'm looking for some easy-understanding docs to read up. Any recommendations?

1

There are 1 answers

0
slebetman On BEST ANSWER

In most javascript test frameworks (including ava) assertion methods are simply functions that throws an error if the asserted condition is not met.

For example the method:

t.true(x, "x must be true");

will simply throw an error if the value of x is 1 or "hello" or false etc. As long as the value of x is not true t.true() will throw an error.

The way most js test frameworks work is to catch all thrown errors and output a nice report.