66 TestContext ,
77} from './setup-context' ;
88import global from './global' ;
9- import hasEmberVersion from './has-ember-version' ;
109import settled from './settled' ;
1110import getTestMetadata from './test-metadata' ;
1211import { runHooks } from './-internal/helper-hooks' ;
@@ -18,9 +17,7 @@ export interface ApplicationTestContext extends TestContext {
1817 element ?: Element | null ;
1918}
2019
21- const CAN_USE_ROUTER_EVENTS = hasEmberVersion ( 3 , 6 ) ;
2220let routerTransitionsPending : boolean | null = null ;
23- const ROUTER = new WeakMap ( ) ;
2421const HAS_SETUP_ROUTER = new WeakMap ( ) ;
2522
2623// eslint-disable-next-line require-jsdoc
@@ -37,33 +34,7 @@ export function isApplicationTestContext(
3734 @returns {(boolean|null) } if there are pending transitions
3835*/
3936export function hasPendingTransitions ( ) : boolean | null {
40- if ( CAN_USE_ROUTER_EVENTS ) {
41- return routerTransitionsPending ;
42- }
43-
44- let context = getContext ( ) ;
45-
46- // there is no current context, we cannot check
47- if ( context === undefined ) {
48- return null ;
49- }
50-
51- let router = ROUTER . get ( context ) ;
52-
53- if ( router === undefined ) {
54- // if there is no router (e.g. no `visit` calls made yet), we cannot
55- // check for pending transitions but this is explicitly not an error
56- // condition
57- return null ;
58- }
59-
60- let routerMicrolib = router . _routerMicrolib || router . router ;
61-
62- if ( routerMicrolib === undefined ) {
63- return null ;
64- }
65-
66- return ! ! routerMicrolib . activeTransition ;
37+ return routerTransitionsPending ;
6738}
6839
6940/**
@@ -90,28 +61,20 @@ export function setupRouterSettlednessTracking() {
9061
9162 let { owner } = context ;
9263 let router : Router | RouterService ;
93- if ( CAN_USE_ROUTER_EVENTS ) {
94- // SAFETY: unfortunately we cannot `assert` here at present because the
95- // class is not exported, only the type, since it is not designed to be
96- // sub-classed. The most we can do at present is assert that it at least
97- // *exists* and assume that if it does exist, it is bound correctly.
98- let routerService = owner . lookup ( 'service:router' ) ;
99- assert ( 'router service is not set up correctly' , ! ! routerService ) ;
100- router = routerService as RouterService ;
101-
102- // track pending transitions via the public routeWillChange / routeDidChange APIs
103- // routeWillChange can fire many times and is only useful to know when we have _started_
104- // transitioning, we can then use routeDidChange to signal that the transition has settled
105- router . on ( 'routeWillChange' , ( ) => ( routerTransitionsPending = true ) ) ;
106- router . on ( 'routeDidChange' , ( ) => ( routerTransitionsPending = false ) ) ;
107- } else {
108- // SAFETY: similarly, this cast cannot be made safer because on the versions
109- // where we fall into this path, this is *also* not an exported class.
110- let mainRouter = owner . lookup ( 'router:main' ) ;
111- assert ( 'router:main is not available' , ! ! mainRouter ) ;
112- router = mainRouter as Router ;
113- ROUTER . set ( context , router ) ;
114- }
64+
65+ // SAFETY: unfortunately we cannot `assert` here at present because the
66+ // class is not exported, only the type, since it is not designed to be
67+ // sub-classed. The most we can do at present is assert that it at least
68+ // *exists* and assume that if it does exist, it is bound correctly.
69+ let routerService = owner . lookup ( 'service:router' ) ;
70+ assert ( 'router service is not set up correctly' , ! ! routerService ) ;
71+ router = routerService as RouterService ;
72+
73+ // track pending transitions via the public routeWillChange / routeDidChange APIs
74+ // routeWillChange can fire many times and is only useful to know when we have _started_
75+ // transitioning, we can then use routeDidChange to signal that the transition has settled
76+ router . on ( 'routeWillChange' , ( ) => ( routerTransitionsPending = true ) ) ;
77+ router . on ( 'routeDidChange' , ( ) => ( routerTransitionsPending = false ) ) ;
11578
11679 // hook into teardown to reset local settledness state
11780 let ORIGINAL_WILL_DESTROY = router . willDestroy ;
@@ -204,8 +167,6 @@ export function currentRouteName(): string {
204167 return currentRouteName ;
205168}
206169
207- const HAS_CURRENT_URL_ON_ROUTER = hasEmberVersion ( 2 , 13 ) ;
208-
209170/**
210171 @public
211172 @returns {string } the applications current url
@@ -220,29 +181,22 @@ export function currentURL(): string {
220181
221182 let router = context . owner . lookup ( 'router:main' ) ;
222183
223- if ( HAS_CURRENT_URL_ON_ROUTER ) {
224- let routerCurrentURL = get ( router , 'currentURL' ) ;
184+ let routerCurrentURL = get ( router , 'currentURL' ) ;
225185
226- // SAFETY: this path is a lie for the sake of the public-facing types. The
227- // framework itself sees this path, but users never do. A user who calls the
228- // API without calling `visit()` will see an `UnrecognizedURLError`, rather
229- // than getting back `null`.
230- if ( routerCurrentURL === null ) {
231- return routerCurrentURL as never as string ;
232- }
186+ // SAFETY: this path is a lie for the sake of the public-facing types. The
187+ // framework itself sees this path, but users never do. A user who calls the
188+ // API without calling `visit()` will see an `UnrecognizedURLError`, rather
189+ // than getting back `null`.
190+ if ( routerCurrentURL === null ) {
191+ return routerCurrentURL as never as string ;
192+ }
233193
234- assert (
235- `currentUrl should be a string, but was ${ typeof routerCurrentURL } ` ,
236- typeof routerCurrentURL === 'string'
237- ) ;
194+ assert (
195+ `currentUrl should be a string, but was ${ typeof routerCurrentURL } ` ,
196+ typeof routerCurrentURL === 'string'
197+ ) ;
238198
239- return routerCurrentURL ;
240- } else {
241- // SAFETY: this is *positively ancient* and should probably be removed at
242- // some point; old routers which don't have `currentURL` *should* have a
243- // `location` with `getURL()` per the docs for 2.12.
244- return ( get ( router , 'location' ) as any ) . getURL ( ) ;
245- }
199+ return routerCurrentURL ;
246200}
247201
248202/**
0 commit comments