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

chai-should: improve contain transformations #501

Merged

Conversation

kristerkari
Copy link
Contributor

@kristerkari kristerkari commented Mar 22, 2023

Hello,

When transforming a large test suite I noticed that the .to.contain transformations are not done very well when there are function calls involved.

In the case when the argument for expect() or .to.contain() is a function call, it would be better to simply transform .to.contain() => .toContain() to avoid any problematic results, which is what my changes do.

Since in Jest's .toContain works on strings and arrays, it should not be needed to transform .to.contain to anything more complicated when we don't know what the result of the function call is.

A real example from the codebase that I'm transforming:

expect(getLink("en")).to.contain(encodeURIComponent("test client name en"));

...gets transformed to:

expect(getLink("en")).toEqual(expect.arrayContaining([encodeURIComponent("test client name en")]));

...and after these changes:

expect(getLink("en")).toContain(encodeURIComponent("test client name en"));

ping @skovhus

@codecov
Copy link

codecov bot commented Mar 22, 2023

Codecov Report

Patch coverage: 75.00% and project coverage change: +0.05 🎉

Comparison is base (87daaa6) 92.39% compared to head (70eb736) 92.45%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #501      +/-   ##
==========================================
+ Coverage   92.39%   92.45%   +0.05%     
==========================================
  Files          26       26              
  Lines        1934     1935       +1     
  Branches      404      403       -1     
==========================================
+ Hits         1787     1789       +2     
  Misses        101      101              
+ Partials       46       45       -1     
Impacted Files Coverage Δ
src/transformers/chai-should.ts 95.10% <75.00%> (+0.32%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Owner

@skovhus skovhus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks

@skovhus skovhus enabled auto-merge (squash) March 22, 2023 11:29
@skovhus skovhus merged commit 5c01c62 into skovhus:main Mar 22, 2023
@kristerkari kristerkari deleted the chai-should-improve-contain-transformation branch March 22, 2023 12:01
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 this pull request may close these issues.

2 participants