Skip to content

Commit

Permalink
fix: validating async functions (#7894) (#7896)
Browse files Browse the repository at this point in the history
## Summary

`jest-validate` distinguishes between sync and async functions, but it should not. Fixes #7894.

## Test plan

```js
const { validate } = require('jest-validate')
assert(validate({ name: async () => {} }, { exampleConfig: { name: () => {} } }).isValid)
assert(validate({ name: () => {} }, { exampleConfig: { name: async () => {} } }).isValid)
assert(validate({ name: async () => {} }, { exampleConfig: { name: async () => {} } }).isValid)
assert(validate({ name: () => {} }, { exampleConfig: { name: () => {} } }).isValid)
```
  • Loading branch information
ehmicky authored and thymikee committed Feb 14, 2019
1 parent 02c0237 commit 0c1d5f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
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

0 comments on commit 0c1d5f9

Please sign in to comment.