import { memoizeLast } from './memoize' ; describe ( 'memoizeLast' , ( ) => { type SumFn = ( a : number , b : number ) => number ; let originalSum ; let memoizedSum ; beforeEach ( ( ) => { originalSum = jest . fn ( ( a , b ) => a + b ) ; memoizedSum = memoizeLast ( originalSum ) ; } ) ; it ( 'should call through function' , ( ) => { expect ( memoizedSum ( 26 , 16 ) ) . toBe ( 42 ) ; expect ( originalSum ) . toHaveBeenCalledWith ( 26 , 16 ) ; } ) ; it ( 'should memoize the last call' , ( ) => { memoizedSum ( 26 , 16 ) ; expect ( originalSum ) . toHaveBeenCalledTimes ( 1 ) ; memoizedSum ( 26 , 16 ) ; expect ( originalSum ) . toHaveBeenCalledTimes ( 1 ) ; } ) ; it ( 'should use parameters as cache keys' , ( ) => { expect ( memoizedSum ( 26 , 16 ) ) . toBe ( 42 ) ; expect ( originalSum ) . toHaveBeenCalledTimes ( 1 ) ; expect ( memoizedSum ( 16 , 26 ) ) . toBe ( 42 ) ; expect ( originalSum ) . toHaveBeenCalledTimes ( 2 ) ; } ) ; } ) ;