Skip to content

Commit

Permalink
remove comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcramer committed Mar 5, 2025
1 parent c619c11 commit c44a961
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 41 deletions.
31 changes: 1 addition & 30 deletions src/identity/hooks/useName.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,24 @@ describe('useName', () => {
it('returns the correct ENS name and loading state', async () => {
const testEnsName = 'test.ens';

// Mock the getEnsName method of the publicClient
mockGetEnsName.mockResolvedValue(testEnsName);

// Use the renderHook function to create a test harness for the useName hook
const { result } = renderHook(() => useName({ address: testAddress }), {
wrapper: getNewReactQueryTestProvider(),
});

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
// Check that the ENS name and loading state are correct
expect(result.current.data).toBe(testEnsName);
expect(result.current.isLoading).toBe(false);
});
});

it('returns the loading state true while still fetching from ens action', async () => {
// Use the renderHook function to create a test harness for the useName hook
const { result } = renderHook(() => useName({ address: testAddress }), {
wrapper: getNewReactQueryTestProvider(),
});

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
// Check that the ENS name and loading state are correct
expect(result.current.data).toBe(undefined);
expect(result.current.isLoading).toBe(true);
});
Expand All @@ -60,20 +53,16 @@ describe('useName', () => {
it('returns the correct ENS name and loading state for custom chain ', async () => {
const testEnsName = 'test.customchain.eth';

// Mock the getEnsName method of the publicClient
mockReadContract.mockResolvedValue(testEnsName);

// Use the renderHook function to create a test harness for the useName hook
const { result } = renderHook(
() => useName({ address: testAddress, chain: base }),
{
wrapper: getNewReactQueryTestProvider(),
},
);

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
// Check that the ENS name and loading state are correct
expect(result.current.data).toBe(testEnsName);
expect(result.current.isLoading).toBe(false);
});
Expand All @@ -83,38 +72,31 @@ describe('useName', () => {
const testCustomChainEnsName = undefined;
const testEnsName = 'ethereum.eth';

// Mock the getEnsName method of the publicClient
mockReadContract.mockResolvedValue(testCustomChainEnsName);
mockGetEnsName.mockResolvedValue(testEnsName);

// Use the renderHook function to create a test harness for the useName hook
const { result } = renderHook(
() => useName({ address: testAddress, chain: base }),
{
wrapper: getNewReactQueryTestProvider(),
},
);

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
// Check that the ENS name and loading state are correct
expect(result.current.data).toBe(testEnsName);
expect(result.current.isLoading).toBe(false);
});
});

it('returns error for unsupported chain ', async () => {
// Use the renderHook function to create a test harness for the useName hook
const { result } = renderHook(
() => useName({ address: testAddress, chain: optimism }),
{
wrapper: getNewReactQueryTestProvider(),
},
);

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
// Check that the ENS name and loading state are correct
expect(result.current.data).toBe(undefined);
expect(result.current.isLoading).toBe(false);
expect(result.current.isError).toBe(true);
Expand All @@ -127,18 +109,15 @@ describe('useName', () => {
it('respects the enabled option in queryOptions', async () => {
const testEnsName = 'test.ens';

// Mock the getEnsName method of the publicClient
mockGetEnsName.mockResolvedValue(testEnsName);

// Use the renderHook function to create a test harness for the useName hook with enabled: false
const { result } = renderHook(
() => useName({ address: testAddress }, { enabled: false }),
{
wrapper: getNewReactQueryTestProvider(),
},
);

// The query should not be executed
expect(result.current.isLoading).toBe(false);
expect(result.current.isFetched).toBe(false);
expect(mockGetEnsName).not.toHaveBeenCalled();
Expand All @@ -147,42 +126,34 @@ describe('useName', () => {
it('uses the default query options when no queryOptions are provided', async () => {
const testEnsName = 'test.ens';

// Mock the getEnsName method of the publicClient
mockGetEnsName.mockResolvedValue(testEnsName);

// Use the renderHook function to create a test harness for the useName hook
renderHook(() => useName({ address: testAddress }), {
wrapper: getNewReactQueryTestProvider(),
});

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
// Check that the default query options were used
expect(mockGetEnsName).toHaveBeenCalled();
});
});

it('merges custom queryOptions with default options', async () => {
const testEnsName = 'test.ens';
const customCacheTime = 120000; // 2 minutes
const customCacheTime = 120000;

// Mock the getEnsName method of the publicClient
mockGetEnsName.mockResolvedValue(testEnsName);

// Use the renderHook function to create a test harness for the useName hook with custom cacheTime
const { result } = renderHook(
() => useName({ address: testAddress }, { cacheTime: customCacheTime }),
{
wrapper: getNewReactQueryTestProvider(),
},
);

// Wait for the hook to finish fetching the ENS name
await waitFor(() => {
expect(result.current.data).toBe(testEnsName);
});

// The query should be executed with the custom cacheTime
expect(mockGetEnsName).toHaveBeenCalled();
});
});
12 changes: 1 addition & 11 deletions src/identity/hooks/useSocials.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,47 @@ describe('useSocials', () => {
});

it('respects the enabled option in queryOptions', async () => {
// Use the renderHook function to create a test harness for the useSocials hook with enabled: false
const { result } = renderHook(
() => useSocials({ ensName: testEnsName }, { enabled: false }),
{
wrapper: getNewReactQueryTestProvider(),
},
);

// The query should not be executed
expect(result.current.isLoading).toBe(false);
expect(result.current.isFetched).toBe(false);
expect(mockGetSocials).not.toHaveBeenCalled();
});

it('uses the default query options when no queryOptions are provided', async () => {
// Mock the getSocials function to return some data
mockGetSocials.mockResolvedValue({
twitter: 'twitterHandle',
github: 'githubUsername',
farcaster: 'farcasterUsername',
website: 'https://example.com',
});

// Use the renderHook function to create a test harness for the useSocials hook
const { result } = renderHook(() => useSocials({ ensName: testEnsName }), {
wrapper: getNewReactQueryTestProvider(),
});

// Wait for the hook to finish fetching the socials
await waitFor(() => {
expect(result.current.isLoading).toBe(false);
});

// The query should be executed with the default options
expect(mockGetSocials).toHaveBeenCalled();
});

it('merges custom queryOptions with default options', async () => {
const customStaleTime = 60000; // 1 minute
const customStaleTime = 60000;

// Mock the getSocials function to return some data
mockGetSocials.mockResolvedValue({
twitter: 'twitterHandle',
github: 'githubUsername',
farcaster: 'farcasterUsername',
website: 'https://example.com',
});

// Use the renderHook function to create a test harness for the useSocials hook with custom staleTime
const { result } = renderHook(
() =>
useSocials({ ensName: testEnsName }, { staleTime: customStaleTime }),
Expand All @@ -105,12 +97,10 @@ describe('useSocials', () => {
},
);

// Wait for the hook to finish fetching the socials
await waitFor(() => {
expect(result.current.isLoading).toBe(false);
});

// The query should be executed with the custom staleTime
expect(mockGetSocials).toHaveBeenCalled();
});
});

0 comments on commit c44a961

Please sign in to comment.