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
Refactor fusion-plugin-react-router to make depending on browser history easier #738
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ import RouterPlugin, { | |
RouterProviderToken, | ||
RouterToken, | ||
GetStaticContextToken, | ||
BrowserHistoryToken, | ||
browserHistoryPlugin, | ||
} from '../src/plugin'; | ||
|
||
const addRoutePrefix = (ctx, next) => { | ||
|
@@ -412,6 +414,51 @@ if (__BROWSER__) { | |
const simulator = setup(app); | ||
await simulator.render('/'); | ||
}); | ||
|
||
test('Browser History Provider', async () => { | ||
const element = <div />; | ||
|
||
const app = getApp(element); | ||
const UniversalEvents = getMockEvents({ | ||
title: '/', | ||
page: '/', | ||
}); | ||
|
||
let middlewareHistory; | ||
let providerHistory; | ||
|
||
app.register(UniversalEventsToken, UniversalEvents); | ||
app.register(BrowserHistoryToken, browserHistoryPlugin); | ||
app.register( | ||
createPlugin({ | ||
deps: { | ||
history: BrowserHistoryToken, | ||
}, | ||
provides({history}) { | ||
expect(history).toBeTruthy(); | ||
providerHistory = history; | ||
}, | ||
}) | ||
); | ||
|
||
app.middleware( | ||
{ | ||
router: RouterToken, | ||
}, | ||
({router}) => (ctx, next) => { | ||
const {history} = router.from(ctx); | ||
expect(history).toBeTruthy(); | ||
middlewareHistory = history; | ||
return next(); | ||
} | ||
); | ||
const simulator = setup(app); | ||
await simulator.render('/'); | ||
|
||
expect(middlewareHistory).toBe(providerHistory); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mostly just want to assert that the instance is the same regardless of where you get it. Is there anything else I should add to the tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is good |
||
|
||
cleanup(); | ||
}); | ||
} | ||
|
||
function getMockEvents({ | ||
|
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.
@ganemone – I made my best efforts here in terms of the docs. Let me know if you have feedback.