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

Matchers very slow for large objects #544

Closed
overlookmotel opened this issue Dec 27, 2022 · 0 comments · Fixed by #545
Closed

Matchers very slow for large objects #544

overlookmotel opened this issue Dec 27, 2022 · 0 comments · Fixed by #545

Comments

@overlookmotel
Copy link
Contributor

Bug

  • package version: 3.2.0
  • node version: 16.18.1
  • npm version: 8.19.2

Relevant code or config:

const obj = {};
for (let i = 0; i < 100000; i++) {
  obj[`_${i}`] = i;
}

it('is an object', () => {
  expect(obj).toBeObject();
});

This test takes approx 7 seconds to complete. NB that's 7 secs just to run the expectation, not including building the object.

Reason is that toBeObject creates both the pass and fail messages even if the test passes. This includes calling printReceived() on the input, and when the input is large, this takes a long time.

Neither message is used when the test passes, so this is unnecessary.

Pretty much all the other matchers are affected by the same issue.

I will submit a PR to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant