Back to Qunit

assert.ok()

docs/api/assert/ok.md

2.26.0888 B
Original Source

ok( state, message = "" )

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

namedescription
stateExpression being tested
message (string)Short description

This assertion requires only one argument. If the argument evaluates 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', 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');
});