|
1 |
| -import React from 'react' |
2 |
| -import ReactDOMServer from 'react-dom/server' |
3 |
| -import StaticRouter from 'react-router/StaticRouter' |
4 |
| -import matchRoutes from '../matchRoutes' |
5 |
| -import renderRoutes from '../renderRoutes' |
| 1 | +import React from "react"; Has comments. Original line has comments. |
| 2 | +import ReactDOMServer from "react-dom/server"; |
| 3 | +import StaticRouter from "react-router/StaticRouter"; |
| 4 | +import matchRoutes from "../matchRoutes"; |
| 5 | +import renderRoutes from "../renderRoutes"; |
6 | 6 |
|
7 |
| -describe('integration', () => { |
8 |
| - it('generates the same matches in renderRoutes and matchRoutes', () => { |
9 |
| - const rendered = [] |
| 7 | +describe("integration", () => { |
| 8 | + it("generates the same matches in renderRoutes and matchRoutes", () => { |
| 9 | + const rendered = []; |
10 | 10 |
|
11 | 11 | const Comp = ({ match, route: { routes } }) => (
|
12 |
| - rendered.push(match), |
13 |
| - renderRoutes(routes) |
14 |
| - ) |
| 12 | + rendered.push(match), renderRoutes(routes) |
| 13 | + ); |
15 | 14 |
|
16 | 15 | const routes = [
|
17 |
| - { path: '/pepper', |
| 16 | + { |
| 17 | + path: "/pepper", |
18 | 18 | component: Comp,
|
19 | 19 | routes: [
|
20 |
| - { path: '/pepper/:type', |
| 20 | + { |
| 21 | + path: "/pepper/:type", |
21 | 22 | component: Comp,
|
22 | 23 | routes: [
|
23 |
| - { path: '/pepper/:type/scoville', |
| 24 | + { |
| 25 | + path: "/pepper/:type/scoville", |
24 | 26 | component: Comp
|
25 | 27 | }
|
26 | 28 | ]
|
27 | 29 | }
|
28 | 30 | ]
|
29 | 31 | },
|
30 | 32 |
|
31 |
| - { path: undefined, |
| 33 | + { |
| 34 | + path: undefined, |
32 | 35 | component: Comp,
|
33 | 36 | routes: [
|
34 |
| - { path: '/ghost', |
| 37 | + { |
| 38 | + path: "/ghost", |
35 | 39 | component: Comp
|
36 | 40 | }
|
37 | 41 | ]
|
38 | 42 | }
|
39 |
| - ] |
| 43 | + ]; |
40 | 44 |
|
41 |
| - const pathname = '/pepper/jalepeno' |
42 |
| - const branch = matchRoutes(routes, pathname) |
| 45 | + const pathname = "/pepper/jalepeno"; |
| 46 | + const branch = matchRoutes(routes, pathname); |
43 | 47 | ReactDOMServer.renderToString(
|
44 | 48 | <StaticRouter location={pathname} context={{}}>
|
45 | 49 | {renderRoutes(routes)}
|
46 | 50 | </StaticRouter>
|
47 |
| - ) |
48 |
| - expect(branch.length).toEqual(2) |
49 |
| - expect(rendered.length).toEqual(2) |
50 |
| - expect(branch[0].match).toEqual(rendered[0]) |
51 |
| - expect(branch[1].match).toEqual(rendered[1]) |
52 |
| - }) |
| 51 | + ); |
| 52 | + expect(branch.length).toEqual(2); |
| 53 | + expect(rendered.length).toEqual(2); |
| 54 | + expect(branch[0].match).toEqual(rendered[0]); |
| 55 | + expect(branch[1].match).toEqual(rendered[1]); |
| 56 | + }); |
53 | 57 |
|
54 |
| - |
55 |
| - |
56 |
| - it('generates the same matches in renderRoutes and matchRoutes with pathless routes', () => { |
57 |
| - const rendered = [] |
| 58 | + it("generates the same matches in renderRoutes and matchRoutes with pathless routes", () => { |
| 59 | + const rendered = []; |
58 | 60 |
|
59 | 61 | const Comp = ({ match, route: { routes } }) => (
|
60 |
| - rendered.push(match), |
61 |
| - renderRoutes(routes) |
62 |
| - ) |
| 62 | + rendered.push(match), renderRoutes(routes) |
| 63 | + ); |
63 | 64 |
|
64 | 65 | const routes = [
|
65 |
| - { path: '/pepper', |
| 66 | + { |
| 67 | + path: "/pepper", |
66 | 68 | component: Comp,
|
67 | 69 | routes: [
|
68 |
| - { path: '/pepper/:type', |
| 70 | + { |
| 71 | + path: "/pepper/:type", |
69 | 72 | component: Comp,
|
70 | 73 | routes: [
|
71 |
| - { path: '/pepper/:type/scoville', |
| 74 | + { |
| 75 | + path: "/pepper/:type/scoville", |
72 | 76 | component: Comp
|
73 | 77 | }
|
74 | 78 | ]
|
75 | 79 | }
|
76 | 80 | ]
|
77 | 81 | },
|
78 | 82 |
|
79 |
| - { path: undefined, |
| 83 | + { |
| 84 | + path: undefined, |
80 | 85 | component: Comp,
|
81 | 86 | routes: [
|
82 |
| - { path: '/ghost', |
| 87 | + { |
| 88 | + path: "/ghost", |
83 | 89 | component: Comp
|
84 | 90 | }
|
85 | 91 | ]
|
86 | 92 | }
|
87 |
| - ] |
| 93 | + ]; |
88 | 94 |
|
89 |
| - const pathname = '/ghost' |
90 |
| - const branch = matchRoutes(routes, pathname) |
| 95 | + const pathname = "/ghost"; |
| 96 | + const branch = matchRoutes(routes, pathname); |
91 | 97 | ReactDOMServer.renderToString(
|
92 | 98 | <StaticRouter location={pathname} context={{}}>
|
93 | 99 | {renderRoutes(routes)}
|
94 | 100 | </StaticRouter>
|
95 |
| - ) |
96 |
| - expect(branch.length).toEqual(2) |
97 |
| - expect(rendered.length).toEqual(2) |
98 |
| - expect(branch[0].match).toEqual(rendered[0]) |
99 |
| - expect(branch[1].match).toEqual(rendered[1]) |
100 |
| - }) |
101 |
| - |
| 101 | + ); |
| 102 | + expect(branch.length).toEqual(2); |
| 103 | + expect(rendered.length).toEqual(2); |
| 104 | + expect(branch[0].match).toEqual(rendered[0]); |
| 105 | + expect(branch[1].match).toEqual(rendered[1]); |
| 106 | + }); |
102 | 107 |
|
103 |
| - |
104 |
| - it('generates the same matches in renderRoutes and matchRoutes with routes using exact', () => { |
105 |
| - const rendered = [] |
| 108 | + it("generates the same matches in renderRoutes and matchRoutes with routes using exact", () => { |
| 109 | + const rendered = []; |
106 | 110 |
|
107 | 111 | const Comp = ({ match, route: { routes } }) => (
|
108 |
| - rendered.push(match), |
109 |
| - renderRoutes(routes) |
110 |
| - ) |
| 112 | + rendered.push(match), renderRoutes(routes) |
| 113 | + ); |
111 | 114 |
|
112 | 115 | const routes = [
|
113 | 116 | // should skip
|
114 | 117 | {
|
115 |
| - path: '/pepper/habanero', |
| 118 | + path: "/pepper/habanero", |
116 | 119 | component: Comp,
|
117 | 120 | exact: true
|
118 | 121 | },
|
119 | 122 | // should match
|
120 | 123 | {
|
121 |
| - path: '/pepper', |
| 124 | + path: "/pepper", |
122 | 125 | component: Comp,
|
123 | 126 | exact: true
|
124 | 127 | }
|
125 |
| - ] |
| 128 | + ]; |
126 | 129 |
|
127 |
| - const pathname = '/pepper' |
128 |
| - const branch = matchRoutes(routes, pathname) |
| 130 | + const pathname = "/pepper"; |
| 131 | + const branch = matchRoutes(routes, pathname); |
129 | 132 | ReactDOMServer.renderToString(
|
130 | 133 | <StaticRouter location={pathname} context={{}}>
|
131 | 134 | {renderRoutes(routes)}
|
132 | 135 | </StaticRouter>
|
133 |
| - ) |
134 |
| - expect(branch.length).toEqual(1) |
135 |
| - expect(rendered.length).toEqual(1) |
136 |
| - expect(branch[0].match).toEqual(rendered[0]) |
137 |
| - }) |
138 |
| - |
139 |
| - |
| 136 | + ); |
| 137 | + expect(branch.length).toEqual(1); |
| 138 | + expect(rendered.length).toEqual(1); |
| 139 | + expect(branch[0].match).toEqual(rendered[0]); |
| 140 | + }); |
140 | 141 |
|
141 |
| - it('generates the same matches in renderRoutes and matchRoutes with routes using exact + strict', () => { |
142 |
| - const rendered = [] |
| 142 | + it("generates the same matches in renderRoutes and matchRoutes with routes using exact + strict", () => { |
| 143 | + const rendered = []; |
143 | 144 |
|
144 | 145 | const Comp = ({ match, route: { routes } }) => (
|
145 |
| - rendered.push(match), |
146 |
| - renderRoutes(routes) |
147 |
| - ) |
| 146 | + rendered.push(match), renderRoutes(routes) |
| 147 | + ); |
148 | 148 |
|
149 | 149 | const routes = [
|
150 | 150 | // should match
|
151 | 151 | {
|
152 |
| - path: '/pepper/', |
| 152 | + path: "/pepper/", |
153 | 153 | component: Comp,
|
154 | 154 | strict: true,
|
155 | 155 | exact: true,
|
156 | 156 | routes: [
|
157 | 157 | // should skip
|
158 | 158 | {
|
159 |
| - path: '/pepper', |
| 159 | + path: "/pepper", |
160 | 160 | component: Comp,
|
161 | 161 | strict: true,
|
162 | 162 | exact: true
|
163 | 163 | }
|
164 | 164 | ]
|
165 | 165 | }
|
166 |
| - ] |
| 166 | + ]; |
167 | 167 |
|
168 |
| - let pathname = '/pepper' |
169 |
| - let branch = matchRoutes(routes, pathname) |
| 168 | + let pathname = "/pepper"; |
| 169 | + let branch = matchRoutes(routes, pathname); |
170 | 170 | ReactDOMServer.renderToString(
|
171 | 171 | <StaticRouter location={pathname} context={{}}>
|
172 | 172 | {renderRoutes(routes)}
|
173 | 173 | </StaticRouter>
|
174 |
| - ) |
175 |
| - expect(branch.length).toEqual(0) |
176 |
| - expect(rendered.length).toEqual(0) |
| 174 | + ); |
| 175 | + expect(branch.length).toEqual(0); |
| 176 | + expect(rendered.length).toEqual(0); |
177 | 177 |
|
178 |
| - pathname = '/pepper/' |
179 |
| - branch = matchRoutes(routes, pathname) |
| 178 | + pathname = "/pepper/"; |
| 179 | + branch = matchRoutes(routes, pathname); |
180 | 180 | ReactDOMServer.renderToString(
|
181 | 181 | <StaticRouter location={pathname} context={{}}>
|
182 | 182 | {renderRoutes(routes)}
|
183 | 183 | </StaticRouter>
|
184 |
| - ) |
| 184 | + ); |
185 | 185 |
|
186 |
| - expect(branch.length).toEqual(1) |
187 |
| - expect(rendered.length).toEqual(1) |
188 |
| - expect(branch[0].match).toEqual(rendered[0]) |
189 |
| - }) |
190 |
| -}) |
| 186 | + expect(branch.length).toEqual(1); |
| 187 | + expect(rendered.length).toEqual(1); |
| 188 | + expect(branch[0].match).toEqual(rendered[0]); |
| 189 | + }); |
| 190 | +}); |