-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jamie Treworgy
committed
Oct 18, 2018
1 parent
4c84514
commit 29e4073
Showing
5 changed files
with
21 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
const toString = Object.prototype.toString; | ||
|
||
export const MultipleValidOptions = Symbol('JEST_MULTIPLE_VALID_OPTIONS'); | ||
const MultipleValidOptionsSymbol = Symbol('JEST_MULTIPLE_VALID_OPTIONS'); | ||
|
||
function validationConditionSingle(option: any, validOption: any): boolean { | ||
return ( | ||
|
@@ -19,19 +19,21 @@ function validationConditionSingle(option: any, validOption: any): boolean { | |
); | ||
} | ||
|
||
export function getConditions(validOption: any) { | ||
export function getValues(validOption: any) { | ||
if ( | ||
Array.isArray(validOption) && | ||
validOption.length && | ||
validOption[0] === MultipleValidOptions | ||
validOption[0] === MultipleValidOptionsSymbol | ||
) { | ||
return validOption.slice(1); | ||
} | ||
return [validOption]; | ||
} | ||
|
||
export function validationCondition(option: any, validOption: any): boolean { | ||
return getConditions(validOption).some(e => | ||
validationConditionSingle(option, e), | ||
); | ||
return getValues(validOption).some(e => validationConditionSingle(option, e)); | ||
} | ||
|
||
export function MultipleValidOptions(...args: Array<any>) { | ||
return [MultipleValidOptionsSymbol, ...args]; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jamietre
Contributor
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I thought about adding a special
$$type
field to this fn so you can check if the value is typeof function and if $$type === symbol, instead of converting this to an array and asserting on its first value