-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathuseLinking.test.ts
36 lines (27 loc) · 1.08 KB
/
useLinking.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {Linking} from 'react-native'
import {act, renderHook} from '@testing-library/react-hooks'
import {useLinking} from './useLinking'
jest.mock('react-native', () => ({
Linking: {
addEventListener: jest.fn((_, fn) => ({remove: jest.fn()})),
getInitialURL: jest.fn(() => Promise.resolve()),
openSettings: jest.fn(() => Promise.resolve()),
canOpenURL: jest.fn(() => Promise.resolve(true)),
openURL: jest.fn((url: string) => Promise.resolve()),
},
}))
describe('useLinking', () => {
it('should return deeplink as null', () => {
const {result, waitForNextUpdate} = renderHook(() => useLinking())
waitForNextUpdate()
expect(result.current.deepLink).toBe(null)
})
it('calls getInitialURL with initial deeplink url', async () => {
const url = 'app://magic_screen'
const getInitialURLSpy = jest.spyOn(Linking, 'getInitialURL')
getInitialURLSpy.mockResolvedValueOnce(url)
const {result, waitForNextUpdate} = renderHook(() => useLinking())
await waitForNextUpdate()
expect(result.current.deepLink).toBe('app://magic_screen')
})
})