Skip to content

Commit

Permalink
Fix #237: Use jQuery#is() for jQuery equality
Browse files Browse the repository at this point in the history
In f1a1f30 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/
  • Loading branch information
mroderick committed Nov 2, 2022
1 parent 12a27d2 commit 15295d9
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/deep-equal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down

0 comments on commit 15295d9

Please sign in to comment.