-
-
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
Allow multilple valid types #7207
Conversation
e46bf2d
to
5c25668
Compare
CHANGELOG.md
Outdated
@@ -15,6 +15,7 @@ | |||
- `[jest-runtime]` If `require` fails without a file extension, print all files that match with one ([#7160](https://github.com/facebook/jest/pull/7160)) | |||
- `[jest-haste-map]` Make `ignorePattern` optional ([#7166](https://github.com/facebook/jest/pull/7166)) | |||
- `[jest-runtime]` Remove `cacheDirectory` from `ignorePattern` for `HasteMap` if not necessary ([#7166](https://github.com/facebook/jest/pull/7166)) | |||
- `[jest-validate]` Add syntax to validate multiple permitted types |
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.
could you include a link to this PR?
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.
Done.
5c25668
to
4c84514
Compare
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.
That's cool! I left some nits to fix.
I'm still thinking about syntax. What do you think is better:
key: [MultipleValidOptions, a, b]
or
key: MultipleValidOptions(a, b)
I'd prefer the second one, but no hard opinions on that.
packages/jest-validate/src/errors.js
Outdated
const validTypes = conditions | ||
.map(getType) | ||
.filter(uniqueFilter()) | ||
.join(' or '); |
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.
how about
const validTypes = Array.from(new Set(conditions.map(getType))).join(' or ');
On syntax, I think I was channeling a JSON-compatible config, but I guess that doesn't really matter if we need to use a If we use a function, it's still going to have to return something that can be identified by the parser, so we'd still probably do something like Actually, I agree this is better, just because it eliminates ambiguity at the use site between this and a real array. |
I think it should be as simple as: function MultipleValidOptions(...args) {
return args
}
MultipleValidOptions.$$type = Symbol('jest-validate-multiple-valid-options'); You get an array of values just like in current implementation |
Not sure I understand... if someone codes
using this definition, then |
Changed per the API you proposed; if there's a more trivial implementation I'm missing here then happy to revise. |
d36ab38
to
29e4073
Compare
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
Split from #7194
Prerequisite to resolving #7180
This PR provides a syntax for
jest-validate
to accept more than one example for a single config value, which can be of different types. This allows overloading config options to accept multiple types.Test plan