Your code also override
collection method with stub.
As I mentioned you suggests to create stubs/mocks for
db manually and
do not use in-memory imitation of MongoDB database?
P.S. I am wondering I cannot find the right way to test module functions that uses database
As I mentioned there are 3 ways to verify test result:
1) Call another (potentially) your module function. Wrong: Your checks should never depends on untested code. Should not be used. Isn't it?
2) Call db functions directly to check if database state has been changed correctly. Right: your are using tested code. This code is not yours. It's easy to test UPDATEs and DELETEs But: How to tests INSERTs?
3) Check (with spy?) if database method has been called. If you tested method has
As I mentioned 3) is the best solution. If your method has only GET or SET (not mixed) -> <работа метода не зависит от > -> Использование db in - memory store можен быть заменено простыми стабами.