Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Latest commit

 

History

History
81 lines (63 loc) · 1.91 KB

File metadata and controls

81 lines (63 loc) · 1.91 KB
layout page-api
title assert.propEqual()
excerpt Compare an object's own properties.
groups
assert
redirect_from
/assert/propEqual/
/propEqual/
version_added 1.11.0

propEqual( actual, expected, message = "" )

Compare an object's own properties using a strict comparison.

name description
actual Expression being tested
expected Known comparison value
message (string) Short description of the actual expression

The propEqual assertion only compares an object's own properties. This means the expected value does not need to be an instance of the same class or otherwise inherit the same prototype. This is in contrast with assert.deepEqual().

This assertion fails if the values differ, or if there are extra properties, or if some properties are missing.

This method is recursive and can compare any nested or complex object via a plain object.

See also

Examples

Compare the property values of two objects.

QUnit.test('example', assert => {
  class Foo {
    constructor () {
      this.x = 1;
      this.y = 2;
    }

    walk () {}
    run () {}
  }

  const foo = new Foo();

  // succeeds, own properties are strictly equal,
  // and inherited properties (such as which constructor) are ignored.
  assert.propEqual(foo, {
    x: 1,
    y: 2
  });
});

Using classic ES5 syntax:

QUnit.test('example', function (assert) {
  function Foo () {
    this.x = 1;
    this.y = 2;
  }
  Foo.prototype.walk = function () {};
  Foo.prototype.run = function () {};

  var foo = new Foo();

  // succeeds, own properties are strictly equal.
  var expected = {
    x: 1,
    y: 2
  };
  assert.propEqual(foo, expected);
});