79164604

Date: 2024-11-06 23:36:23
Score: 0.5
Natty:
Report link

TL;DR: Wrap the dependency and stub your wrapper; don't try to stub the dependency.

The solution I found was to:

// My wrapper module, PubSub.ts
const pubSub = new PubSub()
export async function publishBytes(topicName: string, bytes: Uint8Array): Promise<void> {
    const topic = pubSub.topic(topicName)
    const data = Buffer.from(bytes)
    await topic.publishMessage({ data })
}

// My test code
import * as PubSub from "./PubSub"
sinon.spy(PubSub, "publishBytes")...
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Christopher Simmons