【发布时间】:2019-02-20 10:00:55
【问题描述】:
我的问题是在创建存根实例时如何包含受保护的属性。
在我的开玩笑测试中,我有:
const sandbox = createSandbox();
let manager: SinonStubbedInstance<EntityManager>;
let repo: Repo;
beforeEach(() => {
manager = sandbox.createStubInstance(EntityManager);
repo = new Repo(manager);
});
afterEach(() => sandbox.restore());
试图制作以下的存根:
export declare class EntityManager {
/**
* Connection used by this entity manager.
*/
readonly connection: Connection;
/**
* Custom query runner to be used for operations in this entity manager.
* Used only in non-global entity manager.
*/
readonly queryRunner?: QueryRunner;
/**
* Once created and then reused by en repositories.
*/
protected repositories: Repository<any>[];
/**
* Plain to object transformer used in create and merge operations.
*/
.......
}
所以我似乎无法在存根中包含只读属性和受保护属性。
在“repo = new Repo(manager);”线。 上面的代码产生以下异常:
Argument of type 'SinonStubbedInstance<EntityManager>' is not assignable to parameter of type 'EntityManager'.
Property 'repositories' is missing in type 'SinonStubbedInstance<EntityManager>'.ts(2345)
有没有办法告诉诗浓包含这些属性? 任何帮助将不胜感激。
【问题讨论】:
-
我也有类似的问题。只是用上面的例子稍微解释一下这个问题。 repo.doSomething(){entityManager.doIt()};我只想验证 repo.doSomething 何时被调用,entityManager.doIt() 被调用一次
标签: sinon