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

fix: validating async functions (#7894) #7896

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611))
- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652))
- `[jest-changed-files]` Improve default file selection for Mercurial repos ([#7880](https://github.com/facebook/jest/pull/7880))
- `[jest-validate]` Fix validating async functions ([#7894](https://github.com/facebook/jest/issues/7894))

### Chore & Maintenance

Expand Down
14 changes: 14 additions & 0 deletions packages/jest-validate/src/__tests__/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ test('recursively omits null and undefined config values', () => {
});
});

test.each([
[function() {}, function() {}],
[async function() {}, function() {}],
[function() {}, async function() {}],
[async function() {}, async function() {}],
])(
'treat async and non-async functions as equivalent',
(value, exampleValue) => {
expect(
validate({name: value}, {exampleConfig: {name: exampleValue}}),
).toEqual({hasDeprecationWarnings: false, isValid: true});
},
);

test('respects blacklist', () => {
const warn = console.warn;
console.warn = jest.fn();
Expand Down
1 change: 1 addition & 0 deletions packages/jest-validate/src/condition.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function validationConditionSingle(option: any, validOption: any): boolean {
return (
option === null ||
option === undefined ||
(typeof option === 'function' && typeof validOption === 'function') ||
toString.call(option) === toString.call(validOption)
);
}
Expand Down