@@ -2,20 +2,47 @@ import React from 'react';
22import TestRenderer from 'react-test-renderer' ;
33import { View } from 'react-native' ;
44
5- import { NavigationContext } from '../NavigationContext' ;
5+ import { NavigationConsumer , withNavigation , useNavigation } from '../NavigationContext' ;
66import { Navigation } from '../Navigation.store' ;
77
88describe ( 'NavigationContext' , ( ) => {
9- it ( 'initializes a context with a new navigation store' , ( ) => {
10- const expectedNavigation = new Navigation ( ) ;
11- TestRenderer . create (
12- < NavigationContext . Consumer >
13- { navigation => {
14- expect ( navigation ) . toEqual ( expectedNavigation ) ;
15- return < View /> ;
16- } }
17- </ NavigationContext . Consumer >
18- ) ;
19- expect . assertions ( 1 ) ;
9+ describe ( 'NavigationConsumer' , ( ) => {
10+ it ( 'connects to context and exposes the navigation prop' , ( ) => {
11+ const expectedNavigation = new Navigation ( ) ;
12+ TestRenderer . create (
13+ < NavigationConsumer >
14+ { navigation => {
15+ expect ( navigation ) . toEqual ( expectedNavigation ) ;
16+ return < View /> ;
17+ } }
18+ </ NavigationConsumer >
19+ ) ;
20+ expect . assertions ( 1 ) ;
21+ } ) ;
22+ } ) ;
23+ describe ( 'withNavigation' , ( ) => {
24+ it ( 'connects to context and exposes the navigation prop' , ( ) => {
25+ const expectedNavigation = new Navigation ( ) ;
26+ // @ts -ignore
27+ const ViewWithNavigation = withNavigation ( View ) ;
28+ const testRenderer = TestRenderer . create ( < ViewWithNavigation /> ) ;
29+ // @ts -ignore
30+ expect ( testRenderer . root . children [ 0 ] . props . navigation ) . toEqual ( expectedNavigation ) ;
31+ expect . assertions ( 1 ) ;
32+ } ) ;
33+ } ) ;
34+ describe ( 'useNavigation' , ( ) => {
35+ it ( 'connects to context and exposes the navigation prop' , ( ) => {
36+ const expectedNavigation = new Navigation ( ) ;
37+ const ViewWithNavigation = ( ) => {
38+ const navigation = useNavigation ( ) ;
39+ // @ts -ignore
40+ return < View navigation = { navigation } /> ;
41+ } ;
42+ const testRenderer = TestRenderer . create ( < ViewWithNavigation /> ) ;
43+ // @ts -ignore
44+ expect ( testRenderer . root . children [ 0 ] . props . navigation ) . toEqual ( expectedNavigation ) ;
45+ expect . assertions ( 1 ) ;
46+ } ) ;
2047 } ) ;
2148} ) ;
0 commit comments