Ich möchte eine private Variable in einer Klasse StummelSinon Stub private Variable in Typoskript?
class IPC {
private publisher: redis.RedisClient;
constructor() {
this.publisher = redis.createClient();
}
publish(text: string) {
const msg = {
text: text
};
this.publisher.publish('hello', JSON.stringify(msg));
}
}
Wie kann ich die private Variable publisher
, innerhalb dieser Klasse Stummel? so konnte ich den Code testen, wie unten
it('should return text object',() => {
const ipc = sinon.createStubInstance(IPC);
ipc.publish('world!');
// this will throw error, because ipc.publisher is undefined
assert.deepStrictEqual({
text: 'world!'
}, ipc.publisher.getCall(0).args[0])
})
aber wie kann ich st ub es? – Tim
Meinst du: 'sinon.stub (ipc, 'publisher');'? –
Ich möchte meinen Code wie oben gezeigt testen, aber ich kann es nicht erreichen, es wird sich beschweren 'Kann Eigenschaft 'getCall' von undefined nicht lesen, so weiß ich nicht, wie man den Test erreicht, den ich wollte .. – Tim