Closed alejandrodelarosa closed 5 years ago
The simplest option is probably to return a mock 'pipeline' object, e.g. taking your example:
const mockPipeline = {
del: simple.mock().returnWith(true),
exec: simple.mock() // You could also `.returnWith(true)`, but I don't see the point
};
simple.mock(redis, 'pipeline').returnWith(mockPipeline);
// ...
expect(redis.pipeline.callCount).to.equal(1)
expect(mockPipeline.del.callCount).to.equal(sIds.length + 1)
expect(mockPipeline.exec.callCount).to.equal(1)
Does that make sense?
Another unrelated tip: You do not need to create a promise to resolve with, just resolve the value:
simple.mock(redis, 'lrange').resolveWith(sIds);
Taking the following example.
i'm trying to writte a test like this.
is there a way to also mock the returned value of
const redisPipelineFn = simple.mock(redis, 'pipeline').callOriginal();
so i can do something like
Basically, mock
redis.pipeline().del
andredis.pipeline().exec
Sorry if the title is incorrect.