Skip to content

Commit 0c1d5f9

Browse files
ehmickythymikee
authored andcommitted
fix: validating async functions (#7894) (#7896)
## 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) ```
1 parent 02c0237 commit 0c1d5f9

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- `[jest-cli]` Refactor `-o` and `--coverage` combined ([#7611](https://github.com/facebook/jest/pull/7611))
1212
- `[expect]` Fix custom async matcher stack trace ([#7652](https://github.com/facebook/jest/pull/7652))
1313
- `[jest-changed-files]` Improve default file selection for Mercurial repos ([#7880](https://github.com/facebook/jest/pull/7880))
14+
- `[jest-validate]` Fix validating async functions ([#7894](https://github.com/facebook/jest/issues/7894))
1415

1516
### Chore & Maintenance
1617

packages/jest-validate/src/__tests__/validate.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ test('recursively omits null and undefined config values', () => {
8989
});
9090
});
9191

92+
test.each([
93+
[function() {}, function() {}],
94+
[async function() {}, function() {}],
95+
[function() {}, async function() {}],
96+
[async function() {}, async function() {}],
97+
])(
98+
'treat async and non-async functions as equivalent',
99+
(value, exampleValue) => {
100+
expect(
101+
validate({name: value}, {exampleConfig: {name: exampleValue}}),
102+
).toEqual({hasDeprecationWarnings: false, isValid: true});
103+
},
104+
);
105+
92106
test('respects blacklist', () => {
93107
const warn = console.warn;
94108
console.warn = jest.fn();

packages/jest-validate/src/condition.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function validationConditionSingle(option: any, validOption: any): boolean {
1515
return (
1616
option === null ||
1717
option === undefined ||
18+
(typeof option === 'function' && typeof validOption === 'function') ||
1819
toString.call(option) === toString.call(validOption)
1920
);
2021
}

0 commit comments

Comments
 (0)