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!
1 replies