thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

Cannot overwrite binding with sinon stub #51

Closed jamespedid closed 5 years ago

jamespedid commented 5 years ago

I have a class with an injected property

class MyClass {
    @Inject
     private myProperty: MyDependency
}

Inside of my mocha test I have the following:

Container.bind(MyClass).provider({ get: () => sinon.createStubInstance(MyDependency)});
const myInstance = new MyClass();
myInstance.myMethod(); // throws error because using unmocked version of MyDependency

How can I get this to work?

jamespedid commented 5 years ago

After further investigation I think the problem exists beyond the library.