@@ -22,43 +22,133 @@ describe("A <Route>", () => {
2222 } ) ;
2323 } ) ;
2424
25- it ( "renders when it matches" , ( ) => {
26- const text = "cupcakes" ;
25+ describe ( "with a child element" , ( ) => {
26+ it ( "renders when it matches" , ( ) => {
27+ const text = "cupcakes" ;
2728
28- renderStrict (
29- < MemoryRouter initialEntries = { [ "/cupcakes" ] } >
30- < Route path = "/cupcakes" render = { ( ) => < h1 > { text } </ h1 > } />
31- </ MemoryRouter > ,
32- node
33- ) ;
29+ renderStrict (
30+ < MemoryRouter initialEntries = { [ "/cupcakes" ] } >
31+ < Route path = "/cupcakes" >
32+ < h1 > { text } </ h1 >
33+ </ Route >
34+ </ MemoryRouter > ,
35+ node
36+ ) ;
37+
38+ expect ( node . innerHTML ) . toContain ( text ) ;
39+ } ) ;
40+
41+ it ( "renders when it matches at the root URL" , ( ) => {
42+ const text = "cupcakes" ;
43+
44+ renderStrict (
45+ < MemoryRouter initialEntries = { [ "/" ] } >
46+ < Route path = "/" >
47+ < h1 > { text } </ h1 >
48+ </ Route >
49+ </ MemoryRouter > ,
50+ node
51+ ) ;
52+
53+ expect ( node . innerHTML ) . toContain ( text ) ;
54+ } ) ;
55+
56+ it ( "does not render when it does not match" , ( ) => {
57+ const text = "bubblegum" ;
3458
35- expect ( node . innerHTML ) . toContain ( text ) ;
59+ renderStrict (
60+ < MemoryRouter initialEntries = { [ "/bunnies" ] } >
61+ < Route path = "/flowers" >
62+ < h1 > { text } </ h1 >
63+ </ Route >
64+ </ MemoryRouter > ,
65+ node
66+ ) ;
67+
68+ expect ( node . innerHTML ) . not . toContain ( text ) ;
69+ } ) ;
3670 } ) ;
3771
38- it ( "renders when it matches at the root URL" , ( ) => {
39- const text = "cupcakes" ;
72+ describe ( "with a children function" , ( ) => {
73+ it ( "renders when it matches" , ( ) => {
74+ const text = "cupcakes" ;
4075
41- renderStrict (
42- < MemoryRouter initialEntries = { [ "/" ] } >
43- < Route path = "/" render = { ( ) => < h1 > { text } </ h1 > } />
44- </ MemoryRouter > ,
45- node
46- ) ;
76+ renderStrict (
77+ < MemoryRouter initialEntries = { [ "/cupcakes" ] } >
78+ < Route path = "/cupcakes" children = { ( ) => < h1 > { text } </ h1 > } />
79+ </ MemoryRouter > ,
80+ node
81+ ) ;
82+
83+ expect ( node . innerHTML ) . toContain ( text ) ;
84+ } ) ;
4785
48- expect ( node . innerHTML ) . toContain ( text ) ;
86+ it ( "renders when it matches at the root URL" , ( ) => {
87+ const text = "cupcakes" ;
88+
89+ renderStrict (
90+ < MemoryRouter initialEntries = { [ "/" ] } >
91+ < Route path = "/" children = { ( ) => < h1 > { text } </ h1 > } />
92+ </ MemoryRouter > ,
93+ node
94+ ) ;
95+
96+ expect ( node . innerHTML ) . toContain ( text ) ;
97+ } ) ;
98+
99+ it ( "renders when it does not match" , ( ) => {
100+ const text = "bubblegum" ;
101+
102+ renderStrict (
103+ < MemoryRouter initialEntries = { [ "/bunnies" ] } >
104+ < Route path = "/flowers" children = { ( ) => < h1 > { text } </ h1 > } />
105+ </ MemoryRouter > ,
106+ node
107+ ) ;
108+
109+ expect ( node . innerHTML ) . toContain ( text ) ;
110+ } ) ;
49111 } ) ;
50112
51- it ( "does not render when it does not match" , ( ) => {
52- const text = "bubblegum" ;
113+ describe ( "with a render prop" , ( ) => {
114+ it ( "renders when it matches" , ( ) => {
115+ const text = "cupcakes" ;
53116
54- renderStrict (
55- < MemoryRouter initialEntries = { [ "/bunnies " ] } >
56- < Route path = "/flowers " render = { ( ) => < h1 > { text } </ h1 > } />
57- </ MemoryRouter > ,
58- node
59- ) ;
117+ renderStrict (
118+ < MemoryRouter initialEntries = { [ "/cupcakes " ] } >
119+ < Route path = "/cupcakes " render = { ( ) => < h1 > { text } </ h1 > } />
120+ </ MemoryRouter > ,
121+ node
122+ ) ;
60123
61- expect ( node . innerHTML ) . not . toContain ( text ) ;
124+ expect ( node . innerHTML ) . toContain ( text ) ;
125+ } ) ;
126+
127+ it ( "renders when it matches at the root URL" , ( ) => {
128+ const text = "cupcakes" ;
129+
130+ renderStrict (
131+ < MemoryRouter initialEntries = { [ "/" ] } >
132+ < Route path = "/" render = { ( ) => < h1 > { text } </ h1 > } />
133+ </ MemoryRouter > ,
134+ node
135+ ) ;
136+
137+ expect ( node . innerHTML ) . toContain ( text ) ;
138+ } ) ;
139+
140+ it ( "does not render when it does not match" , ( ) => {
141+ const text = "bubblegum" ;
142+
143+ renderStrict (
144+ < MemoryRouter initialEntries = { [ "/bunnies" ] } >
145+ < Route path = "/flowers" render = { ( ) => < h1 > { text } </ h1 > } />
146+ </ MemoryRouter > ,
147+ node
148+ ) ;
149+
150+ expect ( node . innerHTML ) . not . toContain ( text ) ;
151+ } ) ;
62152 } ) ;
63153
64154 it ( "matches using nextContext when updating" , ( ) => {
0 commit comments