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

[expect]: add empty string check to toThrow matcher #6836

Closed
wants to merge 7 commits into from

Conversation

mattphillips
Copy link
Contributor

Summary

Add a truthy check of the given value when performing toThrowMatchingStringOrRegexp in the toThrow matcher.

@SimenB @thymikee I'm not sure if you want to solve this another way but this seemed this simplest, what do you guys think?

Fixes #6805

Test plan

Added unit tests for empty string.

Copy link
Collaborator

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

LGTM

@SimenB
Copy link
Member

SimenB commented Aug 13, 2018

What about fixing the pattern instead? This will give weird results for falsey values outside of empty strings (such as 0), I think

@mattphillips
Copy link
Contributor Author

@SimenB I've just updated it to default to ^$ for empty strings

@mattphillips
Copy link
Contributor Author

Not sure why the tests are failing now! I'd say something maybe depends on providing empty strings to the escapeStrForRegex??

@SimenB

This comment has been minimized.

@rickhanlonii

This comment has been minimized.

@SimenB

This comment has been minimized.

@SimenB
Copy link
Member

SimenB commented Aug 16, 2018

@mattphillips it doesn't fail locally?

@mattphillips
Copy link
Contributor Author

@SimenB seems like the failing tests are:

    testPathsMatching
      ✕ finds tests matching a pattern via testRegex (89ms)
      ✕ finds tests matching a pattern via testMatch (30ms)

What is weird is that they are failing for me locally on master too (I did a clean clone/install/test)

yarn jest packages/jest-cli/src/__tests__/SearchSource.test.js

screen shot 2018-08-16 at 13 06 52

@SimenB
Copy link
Member

SimenB commented Oct 7, 2018

@mattphillips that fails for me locally as well, not sure why.. However, the only test failing on CI is e2e/__tests__/find_related_files.test.js, mind fixing that? If CI is happy, I'm happy 🙂

@mattphillips
Copy link
Contributor Author

@SimenB I've just spent a chunk of time investigating why this test is failing and couldn't figure it out, so many moving parts 🤣

I've instead moved the check to the matcher itself as we know for sure this is the behaviour we want - let me know what you think?

Expected the function to throw an error matching:
<green>\\"\\"</>
Instead, it threw:
<red> Error</>
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this text include 'apple'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test file defines a custom error with a fixed message for the snapshot - I’ve just reused that which is why it doesn’t say apple

Copy link
Member

Choose a reason for hiding this comment

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

seems silly, doesn't it? Is the error inconsistent if we drop the fixed message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it does a bit! I’ll give it a go and see what happens, maybe it was giving inconsistent line numbers 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah I just noticed this comment above the custom error/stack:

Custom Error class because node versions have different stack trace strings.

Copy link
Member

Choose a reason for hiding this comment

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

is it still valid?

Copy link
Member

Choose a reason for hiding this comment

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

Also, toThrowErrorMatchingSnapshot only snapshots the message, not stack

@SimenB SimenB mentioned this pull request Nov 17, 2018
@SimenB
Copy link
Member

SimenB commented Nov 17, 2018

@mattphillips what's the status here? To fix your failing test locally, run watchman watch-del-all

@mattphillips
Copy link
Contributor Author

Not needed see #6805 (comment)

@mattphillips mattphillips deleted the to-throw branch March 18, 2019 16:55
@github-actions
Copy link

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.
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 May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid toThrow verification
5 participants