-
-
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
Allowed named classes and functions as BlockNames #5154
Allowed named classes and functions as BlockNames #5154
Conversation
describe can now take in classes and functions as the names.
} | ||
|
||
const stringified = descriptor.toString(); | ||
const typeDescriptorMatch = stringified.match(/class|function/); |
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.
If something silly, such as a number or { toString() { return "nope"; }
is passed here, it'll crash. How would you like this function to deal with those error handling cases?
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.
Can you just make the function throw in that case and ask people to provide a string, class or function instead?
Codecov Report
@@ Coverage Diff @@
## master #5154 +/- ##
==========================================
- Coverage 60.65% 60.54% -0.11%
==========================================
Files 201 201
Lines 6695 6707 +12
Branches 3 3
==========================================
Hits 4061 4061
- Misses 2633 2645 +12
Partials 1 1
Continue to review full report at Codecov.
|
Thanks for the PR! I'm curios, is this needed? Why can't you do |
I agree with @SimenB. You can get all the benefits of easy refactoring by doing this manually without having to change Jest. |
Using
@cpojer could you please re-open the PR & issue? |
What about |
Undefined in IE. Two reasons why this is relevant:
|
Hmm, OK. You can override |
Alright, I thought about this some more and have no reason to push back on it. Please add an integration test for this feature before we can merge 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.
Can you add a note to the changelog as well?
This is failing on all CIs, something with the snapshot that was created is wrong (missing a number). It's also weird that you only have a single snapshot as you call |
CHANGELOG.md
Outdated
@@ -8,6 +8,13 @@ None for now | |||
|
|||
### Chore & Maintenance | |||
|
|||
## jest 22.0.5 |
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.
leave this out, it says "master" at the top 🙂
# Conflicts: # CHANGELOG.md
Added a thrown error if what's passed to describe isn't a string, class, or function. I tried adding a snapshot & test case (c4b8343) but CI required source lines including Also: I showed this PR off-hand to a friend and they mentioned they intentionally use numbers as their |
Thanks for making this Pr :) |
const typeDescriptorMatch = stringified.match(/class|function/); | ||
const indexOfNameSpace = | ||
typeDescriptorMatch.index + typeDescriptorMatch[0].length; | ||
const indexOfNameAfterSpace = stringified.search(/\(|\{/, indexOfNameSpace); |
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.
@JoshuaKGoldberg I'm looking at converting this to TS, and it's not happy about the second argument here. It's also not documented at MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search
Should I just remove 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.
@SimenB ha, sure.
Looks like yet another "bug" fixed by TypeScript! 😍
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
describe
can now take in classes and functions as the names. See #5152Test plan
I'm curious about this actually - where would you like me to add tests? It wasn't very clear scanning through the code.
(first Jest PR; still getting used to Flow... expect failures the first few commits!)