From 15295d93358708dc61efe7348e43e968feb56723 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 31 Oct 2022 18:53:54 +0100 Subject: [PATCH] Fix #237: Use jQuery#is() for jQuery equality In f1a1f306018166ad76ab1a1a71d400fc9373f7d0 we added support for [Javascript iteraction protocols][0]. jQuery objects happen to have iteration protocols, so they would trigger the new codepath. However, that code path uses `Array.from` on the input, which doesn't play nice with jQuery's serializer. Luckily, [jQuery has the `is()` method for comparing its objects][1]. [0]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols [1]: https://api.jquery.com/is/ --- lib/deep-equal.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/deep-equal.js b/lib/deep-equal.js index 4a94191..c4760de 100644 --- a/lib/deep-equal.js +++ b/lib/deep-equal.js @@ -191,6 +191,19 @@ function deepEqualCyclic(actual, expectation, match) { return mapsDeeplyEqual; } + // jQuery objects have iteration protocols + // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols + // But, they don't work well with the implementation concerning iterables below, + // so we will detect them and use jQuery's own equality function + /* istanbul ignore next -- this can only be tested in the `test-headless` script */ + if ( + actualObj.constructor && + actualObj.constructor.name === "jQuery" && + typeof actualObj.is === "function" + ) { + return actualObj.is(expectationObj); + } + var isActualNonArrayIterable = isIterable(actualObj) && !isArrayType(actualObj) &&