From 33d59c09c330192ea5df8794f47046e178d9a0be Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Mon, 25 Jun 2018 18:44:33 +0200 Subject: [PATCH] [testharness.js][docs] Improve and document assert_object_equals (#11642) Fixes #10262. --- docs/_writing-tests/testharness-api.md | 5 +++++ resources/testharness.js | 3 +++ 2 files changed, 8 insertions(+) diff --git a/docs/_writing-tests/testharness-api.md b/docs/_writing-tests/testharness-api.md index 737804741bde0f7..92a9536b69030fd 100644 --- a/docs/_writing-tests/testharness-api.md +++ b/docs/_writing-tests/testharness-api.md @@ -700,6 +700,11 @@ Relies on `===`, distinguishes between `-0` and `+0`, and has a specific check f asserts that `expected` is an Array, and `actual` is equal to one of the members i.e. `expected.indexOf(actual) != -1` +### `assert_object_equals(actual, expected, description)` +asserts that `actual` is an object and not null and that all enumerable +properties on `actual` are own properties on `expected` with the same values, +recursing if the value is an object and not null. + ### `assert_array_equals(actual, expected, description)` asserts that `actual` and `expected` have the same length and the value of each indexed property in `actual` is the strictly equal diff --git a/resources/testharness.js b/resources/testharness.js index d4bf2920616fe3f..54379c665a85ae4 100644 --- a/resources/testharness.js +++ b/resources/testharness.js @@ -997,6 +997,9 @@ policies and contribution forms [3]. function assert_object_equals(actual, expected, description) { + assert(typeof actual === "object" && actual !== null, "assert_object_equals", description, + "value is ${actual}, expected object", + {actual: actual}); //This needs to be improved a great deal function check_equal(actual, expected, stack) {