How to mock an Ember-CLI service in an acceptance test?

前端 未结 3 1336
北荒
北荒 2021-01-31 16:51

Quick summary/tldr:

  • It seems that Ember\'s container lookup process + Ember-CLI\'s module resolver doesn\'t allow manually un-registering a service and then regi
3条回答
  •  不知归路
    2021-01-31 17:25

    You can register your mock and inject it instead of the original service.

    application.register('service:mockLogger', mockLogger, {
      instantiate: false
    });
    
    application.inject('route', 'loggerService', 'service:mockLogger');
    application.inject('controller', 'loggerService', 'service:mockLogger');
    

    I use this approach for mocking the torii library in my third-party login acceptance tests. I hope there will be a nicer solution in the future.

提交回复
热议问题