Fix bug causing intermittent GUI unit test failures (#11801)

Fix failing prop test caused by edge case bug in new `findDifferenceIndex`.
This commit is contained in:
Kaz Wesley 2024-12-10 07:05:25 -08:00 committed by GitHub
parent f6a900191a
commit 9f0c0c0257
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -42,7 +42,7 @@ test.prop({
test.prop({
array: fc.array(fc.anything()),
})('findDifferenceIndex (same array)', ({ array }) => {
expect(findDifferenceIndex(array, array)).toEqual(array.length)
expect(findDifferenceIndex(array, array, Object.is)).toEqual(array.length)
})
test.prop({
@ -69,3 +69,8 @@ test.prop({
expect(arr1[differenceIndex]).not.toEqual(arr2[differenceIndex])
}
})
test('findDifferenceIndex (NaN)', () => {
const array = [NaN]
expect(findDifferenceIndex(array, array)).toEqual(0)
})

View File

@ -90,7 +90,8 @@ export function partition<T>(array: Iterable<T>, pred: (elem: T) => boolean): [T
}
/**
* Find smallest index at which two arrays differ. Returns an index past the array (i.e. array length) when both arrays are equal.
* Find smallest index at which two arrays differ. Returns an index past the array (i.e. array length) when both arrays
* are equal. Note that the default comparator uses strict equality, and so `NaN` values will be considered different.
*/
export function findDifferenceIndex<T>(
lhs: T[],