File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ import { test , expect } from 'bun:test' ;
2+ import { selectorToCacheKey } from '../src/index' ;
3+ import type { ArgumentPaths } from '../src/paths.d' ;
4+
5+ type TestFunction = ( a : { x : number ; y : string } , b : number ) => string ;
6+
7+ test ( 'selectorToCacheKey should generate correct cache key' , ( ) => {
8+ const arguments_ : Parameters < TestFunction > = [ { x : 42 , y : 'hello' } , 100 ] ;
9+
10+ const selectorSingle : ArgumentPaths < TestFunction > = '0.x' ;
11+ const expectedSingleKey = JSON . stringify ( { '0.x' : 42 } ) ;
12+ const resultSingle = selectorToCacheKey ( arguments_ , selectorSingle ) ;
13+ expect ( resultSingle ) . toBe ( expectedSingleKey ) ;
14+
15+ const selectorMultiple : ArgumentPaths < TestFunction > = [ '0.x' , '0.y' ] ;
16+ const expectedMultipleKey = JSON . stringify ( { '0.x' : 42 , '0.y' : 'hello' } ) ;
17+ const resultMultiple = selectorToCacheKey ( arguments_ , selectorMultiple ) ;
18+ expect ( resultMultiple ) . toBe ( expectedMultipleKey ) ;
19+
20+ const selectorArray : ArgumentPaths < TestFunction > = [ '0.x' , '1' ] ;
21+ const expectedArrayKey = JSON . stringify ( { '0.x' : 42 , 1 : 100 } ) ;
22+ const resultArray = selectorToCacheKey ( arguments_ , selectorArray ) ;
23+ expect ( resultArray ) . toBe ( expectedArrayKey ) ;
24+ } ) ;
You can’t perform that action at this time.
0 commit comments