Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions packages/tron-wallet-snap/src/caching/useCache.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars,@typescript-eslint/no-shadow */
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { Serializable } from '../utils/serialization/types';
import type { ICache } from './ICache';
import { useCache } from './useCache';
Expand Down Expand Up @@ -90,7 +90,7 @@
let cache: ICache<Serializable>;

// Common cache options
let cacheOptions: CacheOptions;

Check failure on line 93 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cacheOptions' is already declared in the upper scope on line 8 column 7

Check failure on line 93 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cacheOptions' is already declared in the upper scope on line 8 column 7

// Original test functions
let testFunction: () => Promise<string>;
Expand Down Expand Up @@ -158,7 +158,7 @@
describe('when the data is not cached', () => {
it('should cache the result of a function', async () => {
await withUseCache(
async ({ actualExecutionSpy, cache, cachedTestFunction }) => {

Check failure on line 161 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cachedTestFunction' is already declared in the upper scope on line 104 column 7

Check failure on line 161 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cache' is already declared in the upper scope on line 90 column 7

Check failure on line 161 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'actualExecutionSpy' is already declared in the upper scope on line 87 column 7

Check failure on line 161 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cachedTestFunction' is already declared in the upper scope on line 104 column 7

Check failure on line 161 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cache' is already declared in the upper scope on line 90 column 7

Check failure on line 161 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'actualExecutionSpy' is already declared in the upper scope on line 87 column 7
// No cached data
cache.get.mockResolvedValue(undefined);

Expand All @@ -176,7 +176,7 @@
describe('when the data is cached', () => {
it('should return the cached result', async () => {
await withUseCache(
async ({ actualExecutionSpy, cache, cachedTestFunction }) => {

Check failure on line 179 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cachedTestFunction' is already declared in the upper scope on line 104 column 7

Check failure on line 179 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cache' is already declared in the upper scope on line 90 column 7

Check failure on line 179 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'actualExecutionSpy' is already declared in the upper scope on line 87 column 7

Check failure on line 179 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cachedTestFunction' is already declared in the upper scope on line 104 column 7

Check failure on line 179 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cache' is already declared in the upper scope on line 90 column 7

Check failure on line 179 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'actualExecutionSpy' is already declared in the upper scope on line 87 column 7
// Init the cache with some data
cache.get.mockResolvedValue('test');
// jest.spyOn(cache, 'get').mockResolvedValue('test');
Expand All @@ -195,7 +195,7 @@
describe('error handling', () => {
it('should propagate errors from the original function', async () => {
await withUseCache(
async ({ actualExecutionSpy, cachedTestFunction, cache }) => {

Check failure on line 198 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cache' is already declared in the upper scope on line 90 column 7

Check failure on line 198 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cachedTestFunction' is already declared in the upper scope on line 104 column 7

Check failure on line 198 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'actualExecutionSpy' is already declared in the upper scope on line 87 column 7

Check failure on line 198 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cache' is already declared in the upper scope on line 90 column 7

Check failure on line 198 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'cachedTestFunction' is already declared in the upper scope on line 104 column 7

Check failure on line 198 in packages/tron-wallet-snap/src/caching/useCache.test.ts

View workflow job for this annotation

GitHub Actions / Lint, build, and test / Lint (lint:eslint)

'actualExecutionSpy' is already declared in the upper scope on line 87 column 7
const error = new Error('Test error');
actualExecutionSpy.mockRejectedValueOnce(error);

Expand Down Expand Up @@ -318,14 +318,16 @@

describe('function name override', () => {
it('should use the provided function name if given', async () => {
const cachedWithCustomName = useCache(testFunction, cache, {
ttlMilliseconds: 1000,
functionName: 'customFunctionName',
});
await withUseCache(async ({ testFunction, cache }) => {
const cachedWithCustomName = useCache(testFunction, cache, {
ttlMilliseconds: 1000,
functionName: 'customFunctionName',
});

await cachedWithCustomName();
await cachedWithCustomName();

expect(cache.get).toHaveBeenCalledWith('customFunctionName:');
expect(cache.get).toHaveBeenCalledWith('customFunctionName:');
});
});
});

Expand Down
Loading