File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 1+ import { isIn } from './IsIn' ;
2+
3+ describe ( '@IsIn decorator implementation' , ( ) => {
4+ describe ( 'isIn validator' , ( ) => {
5+ it ( 'should accept valid values' , ( ) => {
6+ expect ( isIn ( 'A' , [ 'A' , 'B' ] ) ) . toBe ( true ) ;
7+ expect ( isIn ( 'A' , [ 'B' , 'C' ] ) ) . toBe ( false ) ;
8+ expect ( isIn ( 'A' , [ 1 , 2 ] ) ) . toBe ( false ) ;
9+ } ) ;
10+
11+ it ( 'should not accept invalid values' , ( ) => {
12+ expect ( isIn ( 'A' , 5 as any ) ) . toBe ( false ) ;
13+ expect ( isIn ( 'A' , 'ABC' as any ) ) . toBe ( false ) ;
14+ expect ( isIn ( 'A' , false as any ) ) . toBe ( false ) ;
15+ } ) ;
16+ } ) ;
17+ } ) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export const IS_IN = 'isIn';
77 * Checks if given value is in a array of allowed values.
88 */
99export function isIn ( value : unknown , possibleValues : readonly unknown [ ] ) : boolean {
10- return ! Array . isArray ( possibleValues ) || possibleValues . some ( possibleValue => possibleValue === value ) ;
10+ return Array . isArray ( possibleValues ) && possibleValues . some ( possibleValue => possibleValue === value ) ;
1111}
1212
1313/**
You can’t perform that action at this time.
0 commit comments