Skip to content
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

Prevents apps from stubbing router service in unit tests #304

Open
ef4 opened this issue Jan 19, 2022 · 1 comment
Open

Prevents apps from stubbing router service in unit tests #304

ef4 opened this issue Jan 19, 2022 · 1 comment

Comments

@ef4
Copy link

ef4 commented Jan 19, 2022

This addon eagerly instantiates its service in an instance-initializer:

appInstance.lookup('service:router-scroll');

Which also eagerly instantiates the router service:

But that means it's impossible to write a unit test that stubs the router service, because setupContext from @ember/test-hepers (which is what backs setupTest from 'ember-qunit') will run this initializer before users have a chance to register any overrides.

So if people have unit tests against a stubbed router service, and then they add this addon, those tests break.

@mupkoo
Copy link

mupkoo commented Feb 28, 2023

One thing that you can do to go around this problem is to unregister the router service, before registering your mock

this.owner.unregister('service:router');
this.owner.register('service:router', class extends Service {});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants