@@ -14,7 +14,7 @@ describe("A <Switch>", () => {
14
14
} ) ;
15
15
16
16
describe ( "without a <Router>" , ( ) => {
17
- it ( "throws" , ( ) => {
17
+ it ( "throws an error " , ( ) => {
18
18
spyOn ( console , "error" ) ;
19
19
20
20
expect ( ( ) => {
@@ -34,80 +34,90 @@ describe("A <Switch>", () => {
34
34
node
35
35
) ;
36
36
37
- expect ( node . innerHTML ) . toMatch ( / o n e / ) ;
37
+ expect ( node . innerHTML ) . toContain ( " one" ) ;
38
38
} ) ;
39
39
40
- it ( "renders the first <Redirect from> that matches the URL" , ( ) => {
40
+ it ( "does not render a second <Route> that also matches the URL" , ( ) => {
41
+ ReactDOM . render (
42
+ < MemoryRouter initialEntries = { [ "/one" ] } >
43
+ < Switch >
44
+ < Route path = "/one" render = { ( ) => < h1 > one</ h1 > } />
45
+ < Route path = "/one" render = { ( ) => < h1 > two</ h1 > } />
46
+ </ Switch >
47
+ </ MemoryRouter > ,
48
+ node
49
+ ) ;
50
+
51
+ expect ( node . innerHTML ) . not . toContain ( "two" ) ;
52
+ } ) ;
53
+
54
+ it ( "renders the first <Redirect> that matches the URL" , ( ) => {
41
55
ReactDOM . render (
42
56
< MemoryRouter initialEntries = { [ "/three" ] } >
43
57
< Switch >
44
58
< Route path = "/one" render = { ( ) => < h1 > one</ h1 > } />
45
- < Redirect from = "/four" to = "/one" />
46
- < Redirect from = "/three" to = "/two" />
47
59
< Route path = "/two" render = { ( ) => < h1 > two</ h1 > } />
60
+ < Redirect from = "/three" to = "/two" />
48
61
</ Switch >
49
62
</ MemoryRouter > ,
50
63
node
51
64
) ;
52
65
53
- expect ( node . innerHTML ) . toMatch ( / t w o / ) ;
66
+ expect ( node . innerHTML ) . toContain ( " two" ) ;
54
67
} ) ;
55
68
56
- it ( "does not render a second <Route> or < Redirect> that also matches the URL" , ( ) => {
69
+ it ( "does not render a second <Redirect> that also matches the URL" , ( ) => {
57
70
ReactDOM . render (
58
- < MemoryRouter initialEntries = { [ "/one " ] } >
71
+ < MemoryRouter initialEntries = { [ "/three " ] } >
59
72
< Switch >
60
73
< Route path = "/one" render = { ( ) => < h1 > one</ h1 > } />
61
- < Redirect from = "/one" to = "/two" />
62
- < Route path = "/one" render = { ( ) => < h1 > two</ h1 > } />
63
74
< Route path = "/two" render = { ( ) => < h1 > two</ h1 > } />
75
+ < Redirect from = "/three" to = "/two" />
76
+ < Redirect from = "/three" to = "/one" />
64
77
</ Switch >
65
78
</ MemoryRouter > ,
66
79
node
67
80
) ;
68
81
69
- expect ( node . innerHTML ) . not . toMatch ( / t w o / ) ;
82
+ expect ( node . innerHTML ) . toContain ( " two" ) ;
70
83
} ) ;
71
84
72
- it ( "renders pathless Routes " , ( ) => {
85
+ it ( "renders a Route with no `path` prop " , ( ) => {
73
86
ReactDOM . render (
74
- < MemoryRouter initialEntries = { [ "/cupcakes " ] } >
87
+ < MemoryRouter initialEntries = { [ "/two " ] } >
75
88
< Switch >
76
- < Route path = "/bubblegum " render = { ( ) => < div > one</ div > } />
77
- < Route render = { ( ) => < div > two</ div > } />
89
+ < Route path = "/one " render = { ( ) => < h1 > one</ h1 > } />
90
+ < Route render = { ( ) => < h1 > two</ h1 > } />
78
91
</ Switch >
79
92
</ MemoryRouter > ,
80
93
node
81
94
) ;
82
95
83
- expect ( node . innerHTML ) . not . toContain ( "one" ) ;
84
96
expect ( node . innerHTML ) . toContain ( "two" ) ;
85
97
} ) ;
86
98
87
- it ( "handles from-less Redirects " , ( ) => {
99
+ it ( "renders a Redirect with no ` from` prop " , ( ) => {
88
100
ReactDOM . render (
89
- < MemoryRouter initialEntries = { [ "/cupcakes " ] } >
101
+ < MemoryRouter initialEntries = { [ "/three " ] } >
90
102
< Switch >
91
- < Route path = "/bubblegum " render = { ( ) => < div > bub </ div > } />
92
- < Redirect to = "/bubblegum " />
93
- < Route path = "/cupcakes " render = { ( ) => < div > cup </ div > } />
103
+ < Route path = "/one " render = { ( ) => < h1 > one </ h1 > } />
104
+ < Redirect to = "/one " />
105
+ < Route path = "/two " render = { ( ) => < h1 > two </ h1 > } />
94
106
</ Switch >
95
107
</ MemoryRouter > ,
96
108
node
97
109
) ;
98
110
99
- expect ( node . innerHTML ) . not . toContain ( "cup" ) ;
100
- expect ( node . innerHTML ) . toContain ( "bub" ) ;
111
+ expect ( node . innerHTML ) . toContain ( "one" ) ;
101
112
} ) ;
102
113
103
114
it ( "handles subsequent redirects" , ( ) => {
104
115
ReactDOM . render (
105
116
< MemoryRouter initialEntries = { [ "/one" ] } >
106
117
< Switch >
107
- < Redirect exact from = "/one" to = "/two" />
108
- < Redirect exact from = "/two" to = "/three" />
109
-
110
- < Route path = "/three" render = { ( ) => < div > three</ div > } />
118
+ < Redirect from = "/one" to = "/two" />
119
+ < Redirect from = "/two" to = "/three" />
120
+ < Route path = "/three" render = { ( ) => < h1 > three</ h1 > } />
111
121
</ Switch >
112
122
</ MemoryRouter > ,
113
123
node
0 commit comments