-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
test(query-devtools/utils): add tests for 'mutationSortFns' #10651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+112
β1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π§© Analysis chain
π Web query:
For JavaScript Array.prototype.sort, must a comparator return exactly -1/0/1, or is any negative/zero/positive number valid?π‘ Result:
Any negative/zero/positive number is valid for the comparator in JavaScript Array.prototype.sort. The specification and documentation define the behavior based on the sign of the return value: less than 0 means a before b, 0 means equal (original order preserved where stable), greater than 0 means a after b [1][2][3]. Examples like numeric sorting with (a - b), which can return values like -60, are standard and recommended [4][1]. MDN explicitly uses < 0, === 0, > 0 in its table, not requiring exactly -1/0/1 [1]. While examples often show -1/0/1 for clarity, any value with the correct sign works, as sorting algorithms (like quicksort, timsort) only check the sign [1][5]. The ECMAScript spec's SortCompare abstract operation treats the result based on whether it's less than, equal to, or greater than zero after coercion [6][7]. Returning exactly -1/0/1 is a best practice for readability and to avoid large number precision issues with floats, but not required [1].
Citations:
π Script executed:
Repository: TanStack/query
Length of output: 647
π Script executed:
Repository: TanStack/query
Length of output: 86
π Script executed:
Repository: TanStack/query
Length of output: 148
π Script executed:
Repository: TanStack/query
Length of output: 599
Assert comparator sign, not exact
-1/1.While these comparators currently return exactly
-1and1, the test assertions encode this implementation detail unnecessarily. JavaScript sort comparators only need to return negative/zero/positive values. UsingtoBeGreaterThan(0)andtoBeLessThan(0)makes tests more resilient to refactoringβthe assertions will pass if implementations return other signed values (e.g.,2/-2), which is semantically correct for sorting.Suggested update
π Committable suggestion
π€ Prompt for AI Agents