Skip to content

Commit

Permalink
fix: WC search param test
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Oct 10, 2023
1 parent 2c0b206 commit 664900c
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { useWalletConnectSearchParamUri } from '../useWalletConnectSearchParamUr

describe('useWalletConnectSearchParamUri', () => {
const mockRouter = {
pathname: '/',
query: {},
replace: jest.fn(),
} as unknown as router.NextRouter

beforeEach(() => {
mockRouter.pathname = '/'
mockRouter.query = {}

jest.spyOn(router, 'useRouter').mockReturnValue(mockRouter)
})

Expand All @@ -34,6 +38,9 @@ describe('useWalletConnectSearchParamUri', () => {
})

it('should update the wc uri search param value when setWcUri is called', () => {
mockRouter.pathname = '/test'
mockRouter.query = { test: 'example', wc: 'wc:123' }

const { result } = renderHook(() => useWalletConnectSearchParamUri())
const [wcUri, setWcUri] = result.current

Expand All @@ -44,15 +51,15 @@ describe('useWalletConnectSearchParamUri', () => {
})

expect(mockRouter.replace).toHaveBeenCalledWith({
pathname: mockRouter.pathname,
query: { wc: 'wc:456' },
pathname: '/test',
// Preserves other query params
query: { test: 'example', wc: 'wc:456' },
})

expect(wcUri).toBe('wc:456')
})

it('should remove the wc uri search param when setWcUri is called with null', () => {
mockRouter.query = { wc: 'wc:123' }
it('should remove the wc uri search param when setWcUri is called with null', async () => {
mockRouter.pathname = '/test'
mockRouter.query = { test: 'example', wc: 'wc:123' }

const { result } = renderHook(() => useWalletConnectSearchParamUri())
const [wcUri, setWcUri] = result.current
Expand All @@ -64,10 +71,9 @@ describe('useWalletConnectSearchParamUri', () => {
})

expect(mockRouter.replace).toHaveBeenCalledWith({
pathname: mockRouter.pathname,
query: {},
pathname: '/test',
// Preserves other query params
query: { test: 'example' },
})

expect(wcUri).toBeNull()
})
})

0 comments on commit 664900c

Please sign in to comment.