@@ -17,6 +17,46 @@ describe('utils', () => {
1717 executeOnce ( ) ;
1818 expect ( myFunction ) . toHaveBeenCalledTimes ( 1 ) ;
1919 } ) ;
20+
21+ it ( 'should support arguments' , ( ) => {
22+ const fn = ( num : number , str : string ) => {
23+ return num * 10 + str . length ;
24+ } ;
25+ const fnOnce = once ( fn ) ;
26+ const result = fnOnce ( 5 , 'test' ) ;
27+
28+ expect ( result ) . toBe ( 54 ) ;
29+ } ) ;
30+
31+ it ( 'should ignore arguments if called additional times' , ( ) => {
32+ const fn = ( num : number , str : string ) => {
33+ return num * 10 + str . length ;
34+ } ;
35+ const fnOnce = once ( fn ) ;
36+ const result = fnOnce ( 5 , 'test' ) ;
37+ const result2 = fnOnce ( 2 , 't' ) ;
38+
39+ expect ( result ) . toBe ( 54 ) ;
40+ expect ( result2 ) . toBe ( 54 ) ;
41+ } ) ;
42+
43+ it ( 'should support void functions' , ( ) => {
44+ const fn = ( ) : void => { } ;
45+ const fnOnce = once ( fn ) ;
46+ const result : unknown = fnOnce ( ) ;
47+
48+ expect ( result ) . toBeUndefined ( ) ;
49+ } ) ;
50+
51+ it ( 'should support typed functions' , ( ) => {
52+ const fn = ( ) => {
53+ return 123 ;
54+ } ;
55+ const fnOnce = once ( fn ) ;
56+ const result : number = fnOnce ( ) ;
57+
58+ expect ( result ) . toBe ( 123 ) ;
59+ } ) ;
2060 } ) ;
2161
2262 describe ( '#camelToKebab' , ( ) => {
0 commit comments