DenoDDeno
Powered by
robbieR
Denoโ€ข16mo ago
robbie

What is the best way to mock an internal import?

Hello! I'm working with Deno and I love it so far, but I've run into one issue I can't seem to figure out, regarding testing and mocking internal packages.

I'd like to be able to mock imports from other files, but I'm not sure what the best way to do it is. I have a db.ts file with some Sequelize classes exported (ADatabase and BDatabase), and I use them in another class in another file (ManagerClass in manager.ts). I'd like to be able to mock the Sequelize classes ADatabase and BDatabase, or at least the upsert methods on those classes. But, the examples in the documentation for mocking don't really give examples on how to mock something without reimplementing it (they have their internal functions on a _internals object). Am I supposed to go through my ManagerClass and change how I call each method, so I can easily replace those functions with stubbed/spied versions? Or can I change the self param on stub() to globalThis? I'm really not sure which is the correct way, or if it will even work.

Please help me clear up this confusion. Thank you!
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Best practice to import internal components
danilkinkinDdanilkinkin / help
17mo ago
What is the best way to count values with Deno.Kv?
ร“scarร“ร“scar / help
3y ago
In Deno, what is the best way to simply host static websites?
abcdef38Aabcdef38 / help
3y ago