@@ -52,7 +52,9 @@ const compareComplex = (
5252 ) ;
5353} ;
5454
55- export type HaveTypeTypes =
55+ export type FnComparator = < Actual = unknown > ( actual : Actual , comparators : Comparators ) => boolean ;
56+
57+ export type HaveTypeType =
5658 | 'array'
5759 | 'bigint'
5860 | 'boolean'
@@ -65,7 +67,7 @@ export type HaveTypeTypes =
6567 | 'undefined' ;
6668
6769const comparators = {
68- fn : ( actual : unknown , expected : Comparator ) => expected ( actual , comparators ) ,
70+ fn : ( actual : unknown , comparator : Comparator ) => comparator ( actual , comparators ) ,
6971
7072 exists : ( actual : unknown ) => actual !== undefined ,
7173
@@ -100,7 +102,8 @@ const comparators = {
100102 return false ;
101103 } ,
102104
103- regExp : ( actual : unknown , expected : RegExp ) => new RegExp ( expected ) . test ( String ( actual ) ) ,
105+ regExp : ( actual : unknown , regExpLike : string | RegExp ) =>
106+ new RegExp ( regExpLike ) . test ( String ( actual ) ) ,
104107
105108 greater : ( actual : unknown , expected : number ) => Number ( actual ) > expected ,
106109
@@ -125,31 +128,31 @@ const comparators = {
125128 return actualLength <= expected ;
126129 } ,
127130
128- inRange : ( actual : unknown , expected : [ number , number ] ) => {
129- const [ min , max ] = expected ;
131+ inRange : ( actual : unknown , range : [ number , number ] ) => {
132+ const [ min , max ] = range ;
130133 return Number ( actual ) >= min && Number ( actual ) <= max ;
131134 } ,
132135
133- haveType : ( actual : unknown , expected : HaveTypeTypes ) => {
134- if ( expected === 'array' ) return Array . isArray ( actual ) ;
135- if ( expected === 'null' ) return actual === null ;
136+ haveType : ( actual : unknown , type : HaveTypeType ) => {
137+ if ( type === 'array' ) return Array . isArray ( actual ) ;
138+ if ( type === 'null' ) return actual === null ;
136139 // eslint-disable-next-line valid-typeof
137- return typeof actual === expected ;
140+ return typeof actual === type ;
138141 } ,
139142
140- haveEntries : ( actual : unknown , expected : any [ ] | PlainObject ) => {
141- if ( ! isObjectLike ( actual ) || ! isObjectLike ( expected ) ) {
143+ haveEntries : ( actual : unknown , entry : any [ ] | PlainObject ) => {
144+ if ( ! isObjectLike ( actual ) || ! isObjectLike ( entry ) ) {
142145 return false ;
143146 }
144147
145- const actualFlatten = normalize ( actual ) ;
146- const expectedFlatten = normalize ( expected ) ;
148+ const flattenActual = normalize ( actual ) ;
149+ const flattenEntry = normalize ( entry ) ;
147150
148- return Object . entries ( expectedFlatten ) . every ( ( [ expectedFlattenKey , expectedValue ] ) => {
151+ return Object . entries ( flattenEntry ) . every ( ( [ flattenEntryKey , expectedValue ] ) => {
149152 if ( isComparator ( expectedValue ) ) {
150- return comparators . fn ( actualFlatten [ expectedFlattenKey ] , expectedValue ) ;
153+ return comparators . fn ( flattenActual [ flattenEntryKey ] , expectedValue ) ;
151154 }
152- return comparators . equals ( actualFlatten [ expectedFlattenKey ] , expectedValue ) ;
155+ return comparators . equals ( flattenActual [ flattenEntryKey ] , expectedValue ) ;
153156 } ) ;
154157 }
155158} ;
0 commit comments