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
- import sinon
- stub otherClass
- 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?