-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
expect: Improve report when matcher fails, part 11 #8008
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
For now, I'd say "no". If (when) we add support for Looking forward to your screenshots 😀 |
Example pictures baseline at left and improved at right Matcher name is regular black: Possible future improvement to highlight item found according to deep equality: Can highlight substring in string: Cannot (yet) highlight value in non-array iterable object: Matcher name is regular black: Can highlight item in array: Align expected and received values: Can highlight pattern in string: |
Codecov Report
@@ Coverage Diff @@
## master #8008 +/- ##
==========================================
+ Coverage 64.12% 64.24% +0.12%
==========================================
Files 259 260 +1
Lines 10150 10162 +12
Branches 1754 1764 +10
==========================================
+ Hits 6509 6529 +20
+ Misses 3255 3245 -10
- Partials 386 388 +2
Continue to review full report at Codecov.
|
const converted: any = | ||
isArray || isString ? received : Array.from(received); | ||
if (typeof received === 'string') { | ||
const index = received.indexOf(String(expected)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too lazy to check, but this reads to be like
expect('hello null in the middle').toContain(null)
would pass? Since String(null) === 'null'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good eyes. It is for correct typing of dubious behavior.
- Do you think it should throw matcher error if received is string and expected is not?
- If yes, is that a breaking change that we wait to add at Jest 25.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it fails today, doesn't it? I'd say it's a bug. If an expect fails with "matcher error" or "null is not in string 'null'" shouldn't matter?
Or does expect('hello null in the middle').toContain(null)
pass today?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will double-check but the original code is .indexOf(value)
which implicitly coerces to string:
test('null', () => {
expect('isnullornot'.indexOf(null)).toBe(2);
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I didn't know indexOf
coerced to string! TIL. Same for includes
actually ('isnullornot'.includes(null) === true
). I'd still say it's a false positive, but I don't feel strongly about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think if I include the code and tests commented out, with a comment that we can find: // BREAKING change to include in Jest 25
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For tracking the breaking change to be included, we should create an issue assigned to the milestone like #7749.
I'd prefer not to put significant amounts of commented out code into master, if you've already written it maybe push it to a branch and link that in the issue so it doesn't get lost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to open one - we can stick all the tiny breakages we wanna make there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created #8023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SimenB Do you mean one for all of them? I think I'd prefer separate issues unless there is a group of breaking changes that have something in common. The small issues will already be grouped using the milestone.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
For
.toContain
,.toContainEqual
, and.toMatch
:rejects
orresolves
in matcher hinttoContain
ortoContainEqual
throw matcher errornot
following expected labelFor more information, see discussion with @jeysal in #7795
Your critique about clarity is especially welcome, because I had to wrestle with the code not to add any more
any
type than the one already intoContain
matcher.Design discussion your thoughts are welcome for a possible future pull request:
// indexOf
comment in matcher hint fortoContain
confusing if received is iterable (for example, set) instead of array?.toContain
referential identity fails for item in array but deep equality succeeds, to highlight the item?.toContainEqual
matcher to be less wordy and more neutral (for example, to fix mistake in Redux reducer,.toContain
might fail in first phase of TDD even though referential identity is the correct criterion)Residue for future pull requests:
.toThrow(string | RegExp)
matcher.exec
method in addition to.test
methodTest plan
Updated existing snapshot tests:
.toContain
.toContainEqual
.toMatch
See also pictures in following comment.