Back to Qunit

assert.notEqual()

docs/api/assert/notEqual.md

2.25.01.2 KB
Original Source

notEqual( actual, expected, message = "" )

A loose inequality comparison, checking for non-strict differences between two values.

namedescription
actualExpression being tested
expectedKnown comparison value
message (string)Short description

The notEqual assertion uses the simple inverted comparison operator (!=) to compare the actual and expected values. When they aren't equal, the assertion passes; otherwise, it fails. When it fails, both actual and expected values are displayed in the test result, in addition to a given message.

assert.equal() can be used to test equality.

assert.notStrictEqual() can be used to test strict inequality.

Examples

The simplest assertion example:

js
QUnit.test('passing example', function (assert) {
  const result = '2';

  // succeeds, 1 and 2 are different.
  assert.notEqual(result, 1);
});

QUnit.test('failing example', function (assert) {
  const result = '2';

  // fails, the number 2 and the string "2" are considered equal when
  // compared loosely. Use `assert.notStrictEqual` to consider them different.
  assert.notEqual(result, 2);
});