@@ -5,6 +5,9 @@ import TestRenderer from 'react-test-renderer';
55import { stopCreator } from './utils/stopCreator' ;
66
77import { createCanal } from '../createCanal' ;
8+ import { Subject } from 'rxjs' ;
9+ import { BackContext } from '../Navigation/BackContext' ;
10+ import { IBackEvent } from '../Navigation/BackHandlerDelegate' ;
811
912describe ( '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} ) ;
0 commit comments