Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exact and strict support to renderRoutes #4826

Merged
merged 2 commits into from
Mar 24, 2017
Merged

Conversation

phurytw
Copy link
Contributor

@phurytw phurytw commented Mar 23, 2017

My attempt at writing tests for #4728

Copy link
Contributor

@pshrmn pshrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should be testing renderRoutes directly, not just integration. What I would like to see tested would be two types of routes:

  1. exact
  2. exact and strict

You can test strict without exact, but you just need to make sure that you understand how that works (see https://reacttraining.com/react-router/core/api/Route/strict-bool). The <Route> tests don't actually test this, just strict and exact.

For each one, there should be two cases: one where it should match and one where it should not. For example, this is the <Route exact> test from the react-router package: https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/__tests__/Route-test.js#L240-L270

}
]
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that this second route is necessary.

@phurytw
Copy link
Contributor Author

phurytw commented Mar 23, 2017

I wrote tests for renderRoutes in a separate file. And changed the integration tests I wrote earlier to test exact + strict.

Copy link
Contributor

@pshrmn pshrmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much just requests for style changes. No need to keep the code compact; easy to read code is preferable. Otherwise, I think that it looks good.

rendered.push(route),
renderRoutes(routes)
)
beforeEach(() => rendered = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other before/after each call uses this style.

beforeEach(() => {
  rendered = []
})

component: Comp,
}]

renderToString(<StaticRouter location='/' context={{}}>{renderRoutes(routes)}</StaticRouter>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to cram everything into one line.

renderToString(
  <StaticRouter location='/' context={{}}>
    {renderRoutes(routes)}
  </StaticRouter>
)

expect(rendered.length).toEqual(1)
expect(rendered[0]).toMatch(routeToMatch)
})
describe('Switch usage', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a blank line before the describe.

expect(rendered.length).toEqual(1)
expect(rendered[0]).toMatch(routeToMatch)
})
it('renders the first matched route in nested routes', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line here, too.

@phurytw
Copy link
Contributor Author

phurytw commented Mar 24, 2017

Should be good to go !

@timdorr
Copy link
Member

timdorr commented Mar 24, 2017

That's a lot of tests! LGTM too. Good work, @lith-light-g!

@amurdock
Copy link

Any idea when this PR will find its way into a release ... would really help me out with a server rendering example I'm writing?

@lennerd
Copy link

lennerd commented Apr 7, 2017

+1 for more info when this will be released.

@amurdock
Copy link

amurdock commented Apr 7, 2017

If anyone is interested I've forked and published as @amurdock/react-router-config until the next release.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants