-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Throw on invalid elements in JSX route configs (#326)
Also, improve test coverage.
- Loading branch information
Showing
7 changed files
with
138 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`makeRouteConfig should error on non-element children 1`] = `"\`,\` is not a valid React element"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import delay from 'delay'; | ||
import MemoryProtocol from 'farce/lib/MemoryProtocol'; | ||
import React from 'react'; | ||
import ReactTestUtils from 'react-dom/test-utils'; | ||
|
||
import createFarceRouter from '../src/createFarceRouter'; | ||
import Redirect from '../src/Redirect'; | ||
import RedirectException from '../src/RedirectException'; | ||
|
||
import { InstrumentedResolver } from './helpers'; | ||
|
||
describe('redirect', () => { | ||
async function assertRedirect(fooRoute) { | ||
const Router = createFarceRouter({ | ||
historyProtocol: new MemoryProtocol('/foo'), | ||
routeConfig: [ | ||
fooRoute, | ||
{ | ||
path: '/bar', | ||
render: () => <div className="bar" />, | ||
}, | ||
], | ||
}); | ||
|
||
const resolver = new InstrumentedResolver(); | ||
const instance = ReactTestUtils.renderIntoDocument( | ||
<Router resolver={resolver} />, | ||
); | ||
|
||
await resolver.done; | ||
await delay(10); | ||
|
||
ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'bar'); | ||
} | ||
|
||
it('should support static redirects', async () => { | ||
await assertRedirect( | ||
new Redirect({ | ||
from: '/foo', | ||
to: '/bar', | ||
}), | ||
); | ||
}); | ||
|
||
it('should support function redirects', async () => { | ||
await assertRedirect( | ||
new Redirect({ | ||
from: '/foo', | ||
to: ({ location }) => location.pathname.replace('foo', 'bar'), | ||
}), | ||
); | ||
}); | ||
|
||
it('should support throwing RedirectException in route render method', async () => { | ||
await assertRedirect({ | ||
path: '/foo', | ||
render: () => { | ||
throw new RedirectException('/bar'); | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters