Documentation

QUnit/expect

From jQuery JavaScript Library

Jump to: navigation, search

« Back to QUnit

expect( amount )

Specify how many assertions are expected to run within a test.
Most useful when testing async code, where a failure usually prevents assertions to run at all.
Arguments:
amountInteger
The number of assertions you expect to run.

Examples:
The getJSON call may fail, so the equals-assertion is never run. To make sure the test fails, expect is called to specify that there should be at least one assertion.

test("a test", function() {
  expect(1);
  stop();
  $.getJSON("/someurl", function(result) {
    equals(result.value, "someExpectedValue");
    start();
  });
});

NameType