-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)
Description
Describe the bug
When adding a custom equality tester in vitest.setup, for example
function numberEquality(actual, expected) {
return typeof expected === 'number' ? actual === expected : undefined;
}
expect.addEqualityTesters([
numberEquality
]);
it is not relayed to typed-array values in toStrictEqual matches.
A patch to fix the issue would be
diff --git a/node_modules/@vitest/expect/dist/index.js b/node_modules/@vitest/expect/dist/index.js
index 868ffa8..c9c2d0e 100644
--- a/node_modules/@vitest/expect/dist/index.js
+++ b/node_modules/@vitest/expect/dist/index.js
@@ -433,7 +433,7 @@ function iterableEquality(a, b, customTesters = [], aStack = [], bStack = []) {
if (!isImmutableList(a) && !isImmutableOrderedKeyed(a) && !isImmutableOrderedSet(a) && !isImmutableRecord(a)) {
const aEntries = Object.entries(a);
const bEntries = Object.entries(b);
- if (!equals(aEntries, bEntries)) {
+ if (!equals(aEntries, bEntries, filteredCustomTesters)) {
return false;
}
}
Reproduction
describe('the numberEquality equality tester', () => {
// works
it('attest equality of -0 and +0 within arrays', () => {
expect([-0, 0, 0]).toStrictEqual([0, -0, 0]);
});
// fails without patch
it('attest equality of -0 and +0 within typed arrays', () => {
expect(Float64Array.of(-0, 0, 0)).toStrictEqual(Float64Array.of(0, -0, 0));
});
});
System Info
System:
OS: Linux 6.6 Gentoo Linux
Binaries:
Node: 20.12.1 - /usr/bin/node
npm: 10.5.0 - /usr/bin/npm
npmPackages:
@vitest/coverage-istanbul: 2.0.2 => 2.0.2
@vitest/coverage-v8: 2.0.2 => 2.0.2
@vitest/expect: 2.0.2 => 2.0.2
vite: 5.3.3 => 5.3.3
vitest: 2.0.2 => 2.0.2Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
p3-minor-bugAn edge case that only affects very specific usage (priority)An edge case that only affects very specific usage (priority)