Skip to content

Conversation

ppiyush13
Copy link
Contributor

What

New feature: Test if two strings are equal, ignoring whitespaces in both string.

    expect('SELECT * FROM TABLE WHERE CONDITION').toBeSimilar(`
        SELECT * FROM TABLE
        WHERE CONDITION
    `);

And if the strings are not similar, provide hints to user regarding the differences in strings with color coding.

    expect('.class { cssRule: value }').toBeSimilar(`
        #id {
            cssRule: value
        }
    `);

image

Why

Very often we are asserting over SQL queries, JS code, CSS rules, etc which is very cumbersome due to spaces and newlines. If the strings differs, then it is very hard to rectify the expected string without any hint.

Notes

Added new npm dependency diff to calculate differences in strings.

Housekeeping

  • Unit tests
  • Documentation is up to date
  • No additional lint warnings
  • Typescript definitions are added/updated where relevant

@codecov-io
Copy link

codecov-io commented Jan 30, 2020

Codecov Report

Merging #266 (4e9670a) into main (8505445) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 4e9670a differs from pull request most recent head e8b691d. Consider uploading reports for the commit e8b691d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##              main      #266    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          132       112    -20     
  Lines          780       570   -210     
  Branches       130        99    -31     
==========================================
- Hits           780       570   -210     
Impacted Files Coverage Δ
src/matchers/toBeSimilar/generateHints.js 100.00% <100.00%> (ø)
src/matchers/toBeSimilar/index.js 100.00% <100.00%> (ø)
src/matchers/toBeSimilar/predicate.js 100.00% <100.00%> (ø)
src/utils/index.js 100.00% <0.00%> (ø)
src/matchers/toBeNaN/index.js 100.00% <0.00%> (ø)
src/matchers/toBeNil/index.js 100.00% <0.00%> (ø)
src/matchers/toBeOdd/index.js 100.00% <0.00%> (ø)
src/matchers/toBeDate/index.js 100.00% <0.00%> (ø)
src/matchers/toBeEven/index.js 100.00% <0.00%> (ø)
src/matchers/toBeTrue/index.js 100.00% <0.00%> (ø)
... and 98 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8505445...e8b691d. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Sorry about no response!

Could you rebase this?

package.json Outdated
"pretty-format": "^22.1.0"
},
"dependencies": {
"diff": "^4.0.2",
Copy link
Member

Choose a reason for hiding this comment

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

could we use jest-diff instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can. Changed and added few more changes.
@SimenB Please review

@ppiyush13 ppiyush13 force-pushed the toBeSimilar branch 4 times, most recently from d662eeb to 9f349e1 Compare October 17, 2021 15:45
@ppiyush13 ppiyush13 changed the title Feature: toBeSimilar. Check if two strings are equal irrespective of white-spaces and provide hints if not Feature: toEqualIgnoringWhitespace. Check if two strings are equal irrespective of white-spaces and provide hints if not Oct 17, 2021
@ppiyush13 ppiyush13 requested a review from SimenB October 17, 2021 15:59
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

nice, thanks!

@SimenB SimenB merged commit 8977bca into jest-community:main Oct 18, 2021
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.

3 participants