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

Commit 8f24877

Browse files
committed
✅ (createCanal) test back handler
1 parent 5ce2d35 commit 8f24877

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

src/__tests__/createCanal.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import TestRenderer from 'react-test-renderer';
55
import { stopCreator } from './utils/stopCreator';
66

77
import { createCanal } from '../createCanal';
8+
import { Subject } from 'rxjs';
9+
import { BackContext } from '../Navigation/BackContext';
10+
import { IBackEvent } from '../Navigation/BackHandlerDelegate';
811

912
describe('createCanal', () => {
1013
it('throws an error if first arg is not a Component', () => {
@@ -151,4 +154,35 @@ describe('createCanal', () => {
151154
fullScreenStack: []
152155
});
153156
});
157+
158+
it('passes back events on', () => {
159+
const back$ = new Subject<IBackEvent>();
160+
const spy = jest.fn();
161+
const Canal = createCanal([stopCreator('a'), stopCreator('b')]);
162+
const testRenderer = TestRenderer.create(
163+
<BackContext.Provider value={{ back$ }}>
164+
<Canal a />
165+
</BackContext.Provider>
166+
);
167+
testRenderer.update(
168+
<BackContext.Provider value={{ back$ }}>
169+
<Canal a b />
170+
</BackContext.Provider>
171+
);
172+
// @ts-ignore
173+
testRenderer.root.children[0].instance.back$.subscribe(spy);
174+
back$.next({ target: null });
175+
expect(spy).toHaveBeenCalledWith({
176+
target: 'b'
177+
});
178+
testRenderer.update(
179+
<BackContext.Provider value={{ back$ }}>
180+
<Canal />
181+
</BackContext.Provider>
182+
);
183+
back$.next({ target: null });
184+
expect(spy).toHaveBeenCalledWith({
185+
target: null
186+
});
187+
});
154188
});

src/createCanal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const createCanal = <
3838
implements ICanal {
3939
constructor(props: WithBackContext<CanalComponentProps<Authorizations>>) {
4040
super(props);
41-
const { style, ...nextAuthorizations } = props;
41+
const { style, backContext, ...nextAuthorizations } = props;
4242

4343
/**
4444
* @TODO 19-06-01 Find a way to safely forbid the use of reserved prop `style` in a StopName.

0 commit comments

Comments
 (0)