typescript - Mock exported instances of private classes - Stack Overflow

I have a class "SomeService" which isn't exported. I export the instance which can be us

I have a class "SomeService" which isn't exported. I export the instance which can be used to call functions on it. Basicly a singleton. Here the example

export const someService = new SomeService(otherService.getConfigObject());

Now when I write unit tests (Currently using sinon and mocha) I can't really mock the otherclass like i would like to. In the beforeEach the instance is already created with a real object.

The only thing that worked is

  1. import sinon
  2. stub otherClass
  3. import someService instance

Which seems very hacky and my formatter (correctly) puts the imports on top.

Is there a convenient way to mock the constructor or otherClass to give my instance a mockConfig? Should i reconsider the architecture choice to export created instances?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745307895a4621826.html

相关推荐

  • typescript - Mock exported instances of private classes - Stack Overflow

    I have a class "SomeService" which isn't exported. I export the instance which can be us

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信