I'm trying to stub a class instance using sinon.createStubInstance
but I'm getting an error stating that a private member variable is missing. Of course I can't explicitly set it either because it's a private member.
Example classes:
class Foo {
private readonly bar: string;
constructor(bar: string) {
this.bar = bar;
}
}
class Parent {
foos: Foo[];
constructor(foos: Foo[]) {
this.foos = foos;
}
}
And in the test I'm writing a beforeEach
block:
beforeEach(function () {
const stubFoo = sinon.createStubInstance(Foo);
const stubParent = sinon.createStubInstance(Parent);
stubParent.foos = [stubFoo]; // Tslint error here
});
The Tslint error is:
Property 'bar' is missing in type 'SinonStubbedInstance' but required in type 'Foo'
For the record I'm using Typescript v3.0.3 and Sinon v7.4.1.