[Feature]: `jest-diff` should allow configuring sorting of object keys
See original GitHub issue🚀 Feature Proposal
Allow configuring the object key sorting for jest-diff
. At present it sorts alphabetically. It should allow using the existing sorting, or providing a function to sort before visual diff is generated.
Motivation
I am trying to diff two package.json
files, and it keys are being sorted alphabetically when displaying the diff. This makes it hard to eyeball, because keys are not where you think they will be.
Example
No response
Pitch
There is no way around it with the way jest-diff
is designed.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Sort JavaScript object by key - Stack Overflow
Top voted answer says you can't, then gives a workaround by storing sorted keys in an array, then iterating and printing key value...
Read more >jest-diff | Yarn - Package Manager
Display differences clearly so people can review changes confidently. The diff named export serializes JavaScript values, compares them line-by-line, and ...
Read more >sort-keys - ESLint - Pluggable JavaScript Linter
This rule checks all property definitions of object expressions and verifies that all variables are sorted alphabetically. Examples of incorrect code for this ......
Read more >How to Sort JavaScript Object by Key - W3docs
In this tutorial, we will share a very simple and functional method to sort an array of objects by key. Here is a...
Read more >jest-repl: Versions | Openbase
... [pretty-format] Allow to opt out from sorting object keys with compareKeys: null (#12443). Fixes. [jest-config] Fix testing multiple projects with ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, that seems like a reasonable approach! PR very much welcome 🙂
I believe we’ve always sorted there. The reason is I assume because it’s easier to read objects that are sorted alphabetically, so it seems natural something which prints a “pretty” version of an object would do so