我在node.js中使用typedi
我想知道我能不能做这样的事
const obj = Container.get(MyObj(creds));不是
const obj = new MyObj(creds);我需要使用它,因为要进行jasmine单元测试。我需要同样的东西。
我应该如何在我的单元测试中获得相同的对象呢?
发布于 2020-07-05 00:06:11
@Service()
class MyObj {
@Inject("creds")
creds: any;
}然后你可以像这样注入:
Container.set("creds", creds);
const obj = Container.get(MyObj);
console.log(obj.creds);https://stackoverflow.com/questions/60165548
复制相似问题