-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: π router.route is now overridable via application (#39)
* fix: π router.route is now overridable via application This should resolve bug, where overriden router.route method would not propagate in integration test run, since it is overriden in this plugin also. * test: π fix tests for bind extension * test: π no need to define async when not using await
- Loading branch information
1 parent
1a02913
commit 8f73cc0
Showing
5 changed files
with
50 additions
and
38 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
37 changes: 21 additions & 16 deletions
37
packages/plugin-testing-integration/src/extensions/bind.js
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 |
---|---|---|
@@ -1,21 +1,26 @@ | ||
export default (ns, oc) => { | ||
const pageManager = oc.get('$PageManager'); | ||
const router = oc.get('$Router'); | ||
const nativeRoute = router.route.bind(router); | ||
import { aop, hookName, createHook } from 'to-aop'; | ||
|
||
router.route = (path, ...args) => { | ||
const isFirstNavigation = !pageManager._managedPage.controller; | ||
export default (ns, oc) => { | ||
const Router = oc.get('$Router').constructor; | ||
const routeHook = createHook( | ||
hookName.beforeMethod, | ||
'route', | ||
({ args, context }) => { | ||
const pageManager = oc.get('$PageManager'); | ||
const isFirstNavigation = !pageManager._managedPage.controller; | ||
const path = args[0]; | ||
|
||
// We have to set correct url in jsdom for first application | ||
// navigation to simulate browser behavior, where you | ||
// already have correct url set in address bar. | ||
if (isFirstNavigation) { | ||
/* eslint-disable-next-line no-undef */ | ||
jsdom.reconfigure({ | ||
url: router.getBaseUrl() + path | ||
}); | ||
// We have to set correct url in jsdom for first application | ||
// navigation to simulate browser behavior, where you | ||
// already have correct url set in address bar. | ||
if (isFirstNavigation) { | ||
/* eslint-disable-next-line no-undef */ | ||
jsdom.reconfigure({ | ||
url: context.getBaseUrl() + path | ||
}); | ||
} | ||
} | ||
); | ||
|
||
return nativeRoute(path, ...args); | ||
}; | ||
aop(Router, routeHook); | ||
}; |