Open ef4 opened 2 years ago
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 {});
This addon eagerly instantiates its service in an instance-initializer:
https://github.com/DockYard/ember-router-scroll/blob/2f17728fd82d7d486888df9a09fdc4aae233f294/addon/instance-initializers/ember-router-scroll.js#L3
Which also eagerly instantiates the router service:
https://github.com/DockYard/ember-router-scroll/blob/2f17728fd82d7d486888df9a09fdc4aae233f294/addon/services/router-scroll.js#L72
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 backssetupTest
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.