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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce output for custom objects when using toHaveLength matcher #6519

Closed
eddyerburgh opened this issue Jun 22, 2018 · 8 comments
Closed

Reduce output for custom objects when using toHaveLength matcher #6519

eddyerburgh opened this issue Jun 22, 2018 · 8 comments
Labels

Comments

@eddyerburgh
Copy link
Contributor

馃殌 Feature Proposal

Remove the received output for custom objects that fail a toHaveLength matcher assertion.

Motivation

If you use toHaveLength on a custom object, like an enzyme Wrapper, the output logs all the properties of the object. This makes tests difficult to read.

Example

The same way as before, but no received logging for objects that aren't an Array.

Pitch

Appropriate custom matchers make failing tests more expressive, but error messages for custom objects with toHaveLength are too verbose. It makes failing tests less expressive.

@greypants
Copy link

YES PLEASE! This is out of control:

image

@greypants
Copy link

To be fair, you can opt out of this, and just expect(thing.length).toBe(0)

@mattphillips
Copy link
Contributor

A quick win might be to remove the Received output all together and instead have:

Expected value to have length:
  n
Received length:
  m

A slightly more complicated but better alternative could be to use process.stdout.columns to determine how wide the users terminal is and only print the first N characters of the stringified received value :)

@SimenB
Copy link
Member

SimenB commented Oct 16, 2018

@pedrottimark are you fixing this in your PR?

@johanjq
Copy link

johanjq commented Sep 15, 2020

@greypants thanks for this man, you are amazing

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the Stale label Feb 25, 2022
@github-actions
Copy link

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@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 Apr 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants