question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SimenBcommented, Oct 20, 2021

Yeah, that seems like a reasonable approach! PR very much welcome 🙂

1reaction
SimenBcommented, Oct 19, 2021

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found