Skip to content

Commit 9f0c0c0

Browse files
authored
Fix bug causing intermittent GUI unit test failures (#11801)
Fix failing prop test caused by edge case bug in new `findDifferenceIndex`.
1 parent f6a9001 commit 9f0c0c0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

app/gui/src/project-view/util/__tests__/array.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test.prop({
4242
test.prop({
4343
array: fc.array(fc.anything()),
4444
})('findDifferenceIndex (same array)', ({ array }) => {
45-
expect(findDifferenceIndex(array, array)).toEqual(array.length)
45+
expect(findDifferenceIndex(array, array, Object.is)).toEqual(array.length)
4646
})
4747

4848
test.prop({
@@ -69,3 +69,8 @@ test.prop({
6969
expect(arr1[differenceIndex]).not.toEqual(arr2[differenceIndex])
7070
}
7171
})
72+
73+
test('findDifferenceIndex (NaN)', () => {
74+
const array = [NaN]
75+
expect(findDifferenceIndex(array, array)).toEqual(0)
76+
})

app/gui/src/project-view/util/data/array.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export function partition<T>(array: Iterable<T>, pred: (elem: T) => boolean): [T
9090
}
9191

9292
/**
93-
* Find smallest index at which two arrays differ. Returns an index past the array (i.e. array length) when both arrays are equal.
93+
* Find smallest index at which two arrays differ. Returns an index past the array (i.e. array length) when both arrays
94+
* are equal. Note that the default comparator uses strict equality, and so `NaN` values will be considered different.
9495
*/
9596
export function findDifferenceIndex<T>(
9697
lhs: T[],

0 commit comments

Comments
 (0)