Skip to content
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

pretty-format does not support Immutable.Record #3677

Closed
renchap opened this issue May 28, 2017 · 5 comments · Fixed by #3678
Closed

pretty-format does not support Immutable.Record #3677

renchap opened this issue May 28, 2017 · 5 comments · Fixed by #3678

Comments

@renchap
Copy link
Contributor

renchap commented May 28, 2017

Do you want to request a feature or report a bug?

This is a feature

What is the current behavior?

import { Record } from 'immutable';
import prettyFormat from 'pretty-format';

const TestRecord = Record({ attribute: null });
const x = new TestRecord();

console.log(x);
// => Record { "attribute": null }

console.log(prettyFormat(x));
// =>
// Object {
//   "attribute": null,
// }

What is the expected behavior?

prettyFormat should return something other than an Object, probably Immutable.Record to be consistent with other Immutable structures.

Use case: I use records in various places of my Redux state (the state being a record itself) and I am using snapshots to test my reducers. I would really like the state to not be serialized as JSON (mostly because this makes the Map & List it contain appear as plain JS objects).

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

pretty-format v20.0.3
immutable.js v3.8.1
Node 7.10.0
MacOS 10.12.5

@thymikee
Copy link
Collaborator

Hey! Would you like to implement it? It should be straight forward once you see how other Immutable entities are written. You'll find the code in plugins directory of pretty-format :)

@renchap
Copy link
Contributor Author

renchap commented May 28, 2017

I started to work on it.

Is this format ok?

const ABRecord = Immutable.Record({a: 1, b: 2}, 'ABRecord');
prettyPrint(new ABRecord());
// => Immutable.Record(ABRecord) {a: 1, b: 2}

const CDRecord = Immutable.Record({c: 1, d: 2});
prettyPrint(new CDRecord());
// => Immutable.Record {c: 1, d: 2}

@renchap renchap changed the title pretty-format does not support Record pretty-format does not support Immutable.Record May 28, 2017
@thymikee
Copy link
Collaborator

thymikee commented May 28, 2017

Looks good to me.

const ABRecord = Immutable.Record({a: 1, b: 2}, 'ABRecord');
prettyPrint(new ABRecord());
// => Immutable.Record "ABRecord" {a: 1, b: 2}
// or
// => Immutable.Record["ABRecord"] {a: 1, b: 2}

How about this?

Also I just checked out how it looks in pretty-immutable, would go like:

const ABRecord = Immutable.Record({a: 1, b: 2}, 'ABRecord');
prettyPrint(new ABRecord());
// => Immutable.ABRecord {a: 1, b: 2}

Pick whatever makes more sense to you.

@renchap
Copy link
Contributor Author

renchap commented May 28, 2017

If you are fine with Immutable.ABRecord {a: 1, b: 2} then it looks the best solution. With a fallback to Immutable.Record if no custom name is defined.
I will create a PR soon.

renchap added a commit to renchap/jest that referenced this issue May 28, 2017
renchap added a commit to renchap/jest that referenced this issue May 28, 2017
cpojer pushed a commit that referenced this issue May 30, 2017
* Add support for Immutable.Record in pretty-format

Fixes #3677

* Extract pushToImmutableArray function
tushardhole pushed a commit to tushardhole/jest that referenced this issue Aug 21, 2017
* Add support for Immutable.Record in pretty-format

Fixes jestjs#3677

* Extract pushToImmutableArray function
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants