Skip to content

Commit c6dc22b

Browse files
committed
fix: add another test
1 parent 758d552 commit c6dc22b

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

packages/@ember/-internals/glimmer/lib/helpers/is-active.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export default class IsActiveHelper extends Helper {
4545
return false;
4646
}
4747

48+
// Also track currentRouteName: during loading/error substates the URL
49+
// doesn't change but the active route name does, so isActive() alone
50+
// (which only consumes currentURL) would miss those transitions.
51+
void this.router.currentRouteName;
52+
4853
const args = queryParams ? [...models, { queryParams }] : [...models];
4954
return this.router.isActive(routeName, ...args);
5055
}

packages/@ember/-internals/glimmer/tests/integration/helpers/router-helpers-test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,50 @@ moduleFor(
257257
await this.visit('/posts/42');
258258
assert.equal(this.$('#result').text(), 'false', 'false for different model id');
259259
}
260+
261+
async ['@test stays false during loading substate (URL unchanged, route name changes)'](
262+
assert
263+
) {
264+
let aboutDefer = RSVP.defer();
265+
266+
this.add(
267+
'route:about',
268+
class extends Route {
269+
model() {
270+
return aboutDefer.promise;
271+
}
272+
}
273+
);
274+
275+
this.add(
276+
'template:about-loading',
277+
precompileTemplate(`<div id="loading-spinner"></div>`, { strictMode: true, scope: () => ({}) })
278+
);
279+
280+
this.add(
281+
'template:application',
282+
precompileTemplate(
283+
`{{outlet}}<span id="about-active">{{isActive "about"}}</span>`,
284+
{ strictMode: true, scope: () => ({ isActive }) }
285+
)
286+
);
287+
288+
await this.visit('/');
289+
assert.equal(this.$('#about-active').text(), 'false', 'false before navigation');
290+
291+
let visitPromise = this.visit('/about');
292+
// While in the loading substate, currentURL is still '/' but
293+
// currentRouteName has changed — isActive must still return false.
294+
assert.equal(
295+
this.$('#about-active').text(),
296+
'false',
297+
'false during loading substate'
298+
);
299+
300+
aboutDefer.resolve();
301+
await visitPromise;
302+
assert.equal(this.$('#about-active').text(), 'true', 'true after model resolves');
303+
}
260304
}
261305
);
262306

0 commit comments

Comments
 (0)