I've recently started using QUnit to unit test my JavaScript and I'm a little confused by a feature in there documentation: expect()
.
According to the docs, expect()
is designed to:
[s]pecify how many assertions are expected to run within a test.
And here's the example they give:
test( "a test", function() {
expect( 2 );
function calc( x, operation ) {
return operation( x );
}
var result = calc( 2, function( x ) {
ok( true, "calc() calls operation function" );
return x * x;
});
equal( result, 4, "2 square equals 4" );
});
The only thing I see here is maintenance nightmare. Every time you add an assertion to a test, you have to update that number or the test will fail. Is there a practical application for this kind of feature?
expect(100)
(or similar) and it should be fine. – Ipomoea