-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBranchSubscriber.test.js
43 lines (35 loc) · 1.57 KB
/
BranchSubscriber.test.js
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
37
38
39
40
41
42
43
import { NativeModules } from 'react-native'
const { RNBranch } = NativeModules
import { BranchSubscriber } from 'react-native-branch'
test('default initializes with no options', () => {
const subscriber = new BranchSubscriber(null)
expect(subscriber.options).toEqual({})
})
test('stores options passed to the constructor', () => {
const subscriber = new BranchSubscriber({
checkCachedEvents: false
})
expect(subscriber.options).toEqual({ checkCachedEvents: false })
})
test('subscribes to init session start events', () => {
const subscriber = new BranchSubscriber({
checkCachedEvents: false,
onOpenStart: ({uri}) => {},
})
subscriber._nativeEventEmitter.addListener = jest.fn((eventType, listener) => {})
subscriber.subscribe()
expect(subscriber._nativeEventEmitter.addListener.mock.calls.length).toBe(1)
expect(subscriber._nativeEventEmitter.addListener.mock.calls[0][0]).toBe(RNBranch.INIT_SESSION_START)
})
test('subscribes to init session success & error events', () => {
const subscriber = new BranchSubscriber({
checkCachedEvents: false,
onOpenComplete: ({params, error, uri}) => {},
})
subscriber._nativeEventEmitter.addListener = jest.fn((eventType, listener) => {})
subscriber.subscribe()
expect(subscriber._nativeEventEmitter.addListener.mock.calls.length).toBe(2)
// TODO: This is brittle because it depends on the order.
expect(subscriber._nativeEventEmitter.addListener.mock.calls[0][0]).toBe(RNBranch.INIT_SESSION_SUCCESS)
expect(subscriber._nativeEventEmitter.addListener.mock.calls[1][0]).toBe(RNBranch.INIT_SESSION_ERROR)
})