As in:
function assert(condition, ...) {
if (!condition)
throw new AssertionException(...);
}
I've seen "expect"s being called "assert"s, but they are not the same thing. An assertion is a hard stop beyond which it doesn't make sense to execute code. For example, here's how I might check with assertions that there's exactly one image element on the page:
var imgs = document.getElementsByTagName('img');
assert(imgs.length).toBe(1);
expect(imgs[0].src).toBe(something);
...
And here's how we have to do it with expectations, in effect duplicating our test:
var imgs = document.getElementsByTagName('img');
expect(imgs.length).toBe(1);
if (imgs.length == 1) {
expect(imgs[0].src).toBe(something);
...
}
Or else the test may fail miserably with an exception instead of a nice assertion:
var imgs = document.getElementsByTagName('img');
expect(imgs.length).toBe(1);
expect(imgs[0].src).toBe(something); // If imgs was empty, ka-boom!
...