An assertion is a function that validates a condition if the condition is not valid; it throws an error that
causes the test to fail. A test method can include one or more assertions; all the assertions have to pass in order that the test method passes. In the first YUI test example, we used the Y.Assert.areEqual
assertion. In this section, the other different built-in assertions provided by YUI Test will be illustrated.
The assert
function takes two parameters. The first parameter is a condition, and the second parameter represents a failure message. It is passed if the condition is true, and when it fails, the failure message is displayed. For example:
Y.assert(10 == 10, "Error ..."); // will pass Y.assert(10 != 10, "Error ..."); // will fail and display an error