From 395957c9cb34969d7f429d7b925c672a133eee3b Mon Sep 17 00:00:00 2001 From: gabrieledm Date: Wed, 26 Aug 2026 15:59:17 +0200 Subject: [PATCH] test: used setup function in 'anonymous functions' tests --- .../src/caching/useCache.test.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/tron-wallet-snap/src/caching/useCache.test.ts b/packages/tron-wallet-snap/src/caching/useCache.test.ts index e59f6acc..d69a17da 100644 --- a/packages/tron-wallet-snap/src/caching/useCache.test.ts +++ b/packages/tron-wallet-snap/src/caching/useCache.test.ts @@ -299,17 +299,20 @@ describe('useCache', () => { describe('anonymous functions', () => { it('should handle anonymous functions with a default name', async () => { - // Anonymous function with no name - const anonymousFunction = async () => actualExecutionSpy(); - Object.defineProperty(anonymousFunction, 'name', { value: null }); - - const cachedAnonymousFunction = useCache(anonymousFunction, cache, { - ttlMilliseconds: 1000, - }); + await withUseCache(async ({ actualExecutionSpy, cache }) => { + // Anonymous function with no name + const anonymousFunction = async (): Promise => + actualExecutionSpy(); + Object.defineProperty(anonymousFunction, 'name', { value: null }); + + const cachedAnonymousFunction = useCache(anonymousFunction, cache, { + ttlMilliseconds: 1000, + }); - await cachedAnonymousFunction(); + await cachedAnonymousFunction(); - expect(cache.get).toHaveBeenCalledWith('anonymousFunction:'); + expect(cache.get).toHaveBeenCalledWith('anonymousFunction:'); + }); }); });