Skip to content
This repository was archived by the owner on Nov 3, 2025. It is now read-only.

Commit 674ae27

Browse files
committed
✅ (StopHOC) test event handling
1 parent bac0a60 commit 674ae27

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

src/__tests__/StopHOC.test.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
import { of } from 'rxjs';
3+
import { View } from 'react-native';
4+
import TestRenderer from 'react-test-renderer';
5+
6+
import { StopHOC } from '../StopHOC';
7+
import { Navigation } from '../Navigation';
8+
9+
describe('StopHOC', () => {
10+
it('creates a Component which pipes back events and filter them based on name', () => {
11+
const spy = jest.fn();
12+
const initialEvent = { target: 'myComponent' };
13+
const back$ = of(initialEvent);
14+
const Stop = StopHOC({ back$ }, undefined, 'myComponent', View, undefined);
15+
const testRenderer = TestRenderer.create(<Stop />);
16+
testRenderer.root.instance.back$.subscribe(spy);
17+
expect(spy).toHaveBeenCalledWith(initialEvent);
18+
});
19+
20+
it('creates a Component which pipes back events and filter them out based on name', () => {
21+
const spy = jest.fn();
22+
const initialEvent = { target: 'notMyComponent' };
23+
const back$ = of(initialEvent);
24+
const Stop = StopHOC({ back$ }, undefined, 'myComponent', View, undefined);
25+
const testRenderer = TestRenderer.create(<Stop />);
26+
testRenderer.root.instance.back$.subscribe(spy);
27+
expect(spy).not.toHaveBeenCalled();
28+
});
29+
30+
it('creates a Component which register the onBack side effect in the Navigation\'s BackHandlerDelegate', () => {
31+
const onBackSpy = jest.fn();
32+
const setOnBackCallbackSpy = jest.spyOn(
33+
Navigation.instance.backHandlerDelegate,
34+
'setOnBackCallback'
35+
);
36+
const initialEvent = { target: 'myComponent' };
37+
const back$ = of(initialEvent);
38+
const Stop = StopHOC({ back$ }, onBackSpy, 'myComponent', View, undefined);
39+
const testRenderer = TestRenderer.create(<Stop />);
40+
testRenderer.root.instance.back$.subscribe();
41+
expect(setOnBackCallbackSpy).toHaveBeenCalledWith(onBackSpy);
42+
});
43+
});

0 commit comments

Comments
 (0)