I have written a nodeJS module mymodule.js
that imports the sqlite module. I now want to write some jest tests so I imported my module.js
into my jest test script but want to mock some of the sqlite
functions such as get()
in a couple of tests. All the examples and tutorials assume we are directly importing the library we want to mock. Can I mock the sqlite functions without creating a system-wide mock even though I am not importing the module?
Asked
Active
Viewed 45 times
0

Andreas Köberle
- 106,652
- 57
- 273
- 297

Mark Tyers
- 2,961
- 4
- 29
- 52
-
Yes, you can. The way it should be done depends on a library (sqlite) and how it's used. Consider providing the code you're testing and tests themselves. – Estus Flask Nov 03 '18 at 11:46
-
As sqlite is a bit more complicated to mock please add your code so its clear what you need to mock. – Andreas Köberle Nov 05 '18 at 07:34