Back to Qunit

assert.ok()

docs/api/assert/ok.md

2.25.0863 B
Original Source

ok( state, message = "" )

A boolean check that passes when the first argument is truthy.

namedescription
stateExpression being tested
message (string)Optional description

If the argument is true or casts to true, the assertion passes; otherwise, it fails.

To strictly compare against boolean true, use assert.true().

For the inverse of ok(), refer to assert.notOk()

Examples

js
QUnit.test('example', function (assert) {
  // success
  assert.ok(true, 'boolean true');
  assert.ok('foo', 'non-empty string');
  assert.ok(1, 'number one');

  // failure
  assert.ok(false, 'boolean false');
  assert.ok('', 'empty string');
  assert.ok(0, 'number zero');
  assert.ok(NaN, 'NaN value');
  assert.ok(null, 'null value');
  assert.ok(undefined, 'undefined value');
});