-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
Wise words from the immortal @vjeux himself https://twitter.com/Vjeux/status/951538552675868673
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,190 +1,190 @@ | ||
import React from 'react' | ||
import ReactDOMServer from 'react-dom/server' | ||
import StaticRouter from 'react-router/StaticRouter' | ||
import matchRoutes from '../matchRoutes' | ||
import renderRoutes from '../renderRoutes' | ||
import React from "react"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mjackson
Author
Member
|
||
import ReactDOMServer from "react-dom/server"; | ||
import StaticRouter from "react-router/StaticRouter"; | ||
import matchRoutes from "../matchRoutes"; | ||
import renderRoutes from "../renderRoutes"; | ||
|
||
describe('integration', () => { | ||
it('generates the same matches in renderRoutes and matchRoutes', () => { | ||
const rendered = [] | ||
describe("integration", () => { | ||
it("generates the same matches in renderRoutes and matchRoutes", () => { | ||
const rendered = []; | ||
|
||
const Comp = ({ match, route: { routes } }) => ( | ||
rendered.push(match), | ||
renderRoutes(routes) | ||
) | ||
rendered.push(match), renderRoutes(routes) | ||
); | ||
|
||
const routes = [ | ||
{ path: '/pepper', | ||
{ | ||
path: "/pepper", | ||
component: Comp, | ||
routes: [ | ||
{ path: '/pepper/:type', | ||
{ | ||
path: "/pepper/:type", | ||
component: Comp, | ||
routes: [ | ||
{ path: '/pepper/:type/scoville', | ||
{ | ||
path: "/pepper/:type/scoville", | ||
component: Comp | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
|
||
{ path: undefined, | ||
{ | ||
path: undefined, | ||
component: Comp, | ||
routes: [ | ||
{ path: '/ghost', | ||
{ | ||
path: "/ghost", | ||
component: Comp | ||
} | ||
] | ||
} | ||
] | ||
]; | ||
|
||
const pathname = '/pepper/jalepeno' | ||
const branch = matchRoutes(routes, pathname) | ||
const pathname = "/pepper/jalepeno"; | ||
const branch = matchRoutes(routes, pathname); | ||
ReactDOMServer.renderToString( | ||
<StaticRouter location={pathname} context={{}}> | ||
{renderRoutes(routes)} | ||
</StaticRouter> | ||
) | ||
expect(branch.length).toEqual(2) | ||
expect(rendered.length).toEqual(2) | ||
expect(branch[0].match).toEqual(rendered[0]) | ||
expect(branch[1].match).toEqual(rendered[1]) | ||
}) | ||
); | ||
expect(branch.length).toEqual(2); | ||
expect(rendered.length).toEqual(2); | ||
expect(branch[0].match).toEqual(rendered[0]); | ||
expect(branch[1].match).toEqual(rendered[1]); | ||
}); | ||
|
||
|
||
|
||
it('generates the same matches in renderRoutes and matchRoutes with pathless routes', () => { | ||
const rendered = [] | ||
it("generates the same matches in renderRoutes and matchRoutes with pathless routes", () => { | ||
const rendered = []; | ||
|
||
const Comp = ({ match, route: { routes } }) => ( | ||
rendered.push(match), | ||
renderRoutes(routes) | ||
) | ||
rendered.push(match), renderRoutes(routes) | ||
); | ||
|
||
const routes = [ | ||
{ path: '/pepper', | ||
{ | ||
path: "/pepper", | ||
component: Comp, | ||
routes: [ | ||
{ path: '/pepper/:type', | ||
{ | ||
path: "/pepper/:type", | ||
component: Comp, | ||
routes: [ | ||
{ path: '/pepper/:type/scoville', | ||
{ | ||
path: "/pepper/:type/scoville", | ||
component: Comp | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
|
||
{ path: undefined, | ||
{ | ||
path: undefined, | ||
component: Comp, | ||
routes: [ | ||
{ path: '/ghost', | ||
{ | ||
path: "/ghost", | ||
component: Comp | ||
} | ||
] | ||
} | ||
] | ||
]; | ||
|
||
const pathname = '/ghost' | ||
const branch = matchRoutes(routes, pathname) | ||
const pathname = "/ghost"; | ||
const branch = matchRoutes(routes, pathname); | ||
ReactDOMServer.renderToString( | ||
<StaticRouter location={pathname} context={{}}> | ||
{renderRoutes(routes)} | ||
</StaticRouter> | ||
) | ||
expect(branch.length).toEqual(2) | ||
expect(rendered.length).toEqual(2) | ||
expect(branch[0].match).toEqual(rendered[0]) | ||
expect(branch[1].match).toEqual(rendered[1]) | ||
}) | ||
|
||
); | ||
expect(branch.length).toEqual(2); | ||
expect(rendered.length).toEqual(2); | ||
expect(branch[0].match).toEqual(rendered[0]); | ||
expect(branch[1].match).toEqual(rendered[1]); | ||
}); | ||
|
||
|
||
it('generates the same matches in renderRoutes and matchRoutes with routes using exact', () => { | ||
const rendered = [] | ||
it("generates the same matches in renderRoutes and matchRoutes with routes using exact", () => { | ||
const rendered = []; | ||
|
||
const Comp = ({ match, route: { routes } }) => ( | ||
rendered.push(match), | ||
renderRoutes(routes) | ||
) | ||
rendered.push(match), renderRoutes(routes) | ||
); | ||
|
||
const routes = [ | ||
// should skip | ||
{ | ||
path: '/pepper/habanero', | ||
path: "/pepper/habanero", | ||
component: Comp, | ||
exact: true | ||
}, | ||
// should match | ||
{ | ||
path: '/pepper', | ||
path: "/pepper", | ||
component: Comp, | ||
exact: true | ||
} | ||
] | ||
]; | ||
|
||
const pathname = '/pepper' | ||
const branch = matchRoutes(routes, pathname) | ||
const pathname = "/pepper"; | ||
const branch = matchRoutes(routes, pathname); | ||
ReactDOMServer.renderToString( | ||
<StaticRouter location={pathname} context={{}}> | ||
{renderRoutes(routes)} | ||
</StaticRouter> | ||
) | ||
expect(branch.length).toEqual(1) | ||
expect(rendered.length).toEqual(1) | ||
expect(branch[0].match).toEqual(rendered[0]) | ||
}) | ||
|
||
|
||
); | ||
expect(branch.length).toEqual(1); | ||
expect(rendered.length).toEqual(1); | ||
expect(branch[0].match).toEqual(rendered[0]); | ||
}); | ||
|
||
it('generates the same matches in renderRoutes and matchRoutes with routes using exact + strict', () => { | ||
const rendered = [] | ||
it("generates the same matches in renderRoutes and matchRoutes with routes using exact + strict", () => { | ||
const rendered = []; | ||
|
||
const Comp = ({ match, route: { routes } }) => ( | ||
rendered.push(match), | ||
renderRoutes(routes) | ||
) | ||
rendered.push(match), renderRoutes(routes) | ||
); | ||
|
||
const routes = [ | ||
// should match | ||
{ | ||
path: '/pepper/', | ||
path: "/pepper/", | ||
component: Comp, | ||
strict: true, | ||
exact: true, | ||
routes: [ | ||
// should skip | ||
{ | ||
path: '/pepper', | ||
path: "/pepper", | ||
component: Comp, | ||
strict: true, | ||
exact: true | ||
} | ||
] | ||
} | ||
] | ||
]; | ||
|
||
let pathname = '/pepper' | ||
let branch = matchRoutes(routes, pathname) | ||
let pathname = "/pepper"; | ||
let branch = matchRoutes(routes, pathname); | ||
ReactDOMServer.renderToString( | ||
<StaticRouter location={pathname} context={{}}> | ||
{renderRoutes(routes)} | ||
</StaticRouter> | ||
) | ||
expect(branch.length).toEqual(0) | ||
expect(rendered.length).toEqual(0) | ||
); | ||
expect(branch.length).toEqual(0); | ||
expect(rendered.length).toEqual(0); | ||
|
||
pathname = '/pepper/' | ||
branch = matchRoutes(routes, pathname) | ||
pathname = "/pepper/"; | ||
branch = matchRoutes(routes, pathname); | ||
ReactDOMServer.renderToString( | ||
<StaticRouter location={pathname} context={{}}> | ||
{renderRoutes(routes)} | ||
</StaticRouter> | ||
) | ||
); | ||
|
||
expect(branch.length).toEqual(1) | ||
expect(rendered.length).toEqual(1) | ||
expect(branch[0].match).toEqual(rendered[0]) | ||
}) | ||
}) | ||
expect(branch.length).toEqual(1); | ||
expect(rendered.length).toEqual(1); | ||
expect(branch[0].match).toEqual(rendered[0]); | ||
}); | ||
}); |
8 comments
on commit e6f9017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those beautiful semicolons 😍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this breaks pretty much every PR :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@timdorr Fixing them is as easy as running prettier --write
. No customizations whatsoever
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be best to make prettier
a dev dep and add scripts to the packages so that it is easy for anyone making a PR to have their code correctly formatted. I've also seen some projects setup prettier to run pre-commit, although I'm not sure if you want that behavior here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just that many are old and abandoned, so no one is at the wheel to run that command.
Note: I'm a Prettier user via text editor plugin, so I'm on board with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pshrmn We landed that on Redux in reduxjs/redux#2676. Works well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to use single quote and no semi option. They are meant to be used.