Closed vitorvd closed 1 month ago
Not able to understand the reason for the error. https://www.sammeechward.com/mocking-a-database-with-jest-in-javascript
It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
It seems there has been no activity on this issue for a while, and it is being closed. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.
Details
I'm trying to get 100% of coverage in my code and I have to test the repository layer, so: I have a file called
todoRepository.js
:And I have my test called
todoRepository.test.js
:But when I tried run my tests, I got this error:
But I didn't understand it because I'm mocking the return value from find with:
The line
db.addCollection('schedule')
returns a classLokiEventEmitter
, such as:I believe that I'm getting this error due to method
find
is outside fromaddCollection
. I think I have to create of a mock fromLokiEventEmitter
class with thefind
method, but I don't know how to do it.Node.js version
20.5.1
Example code
No response
Operating system
Linux 6.2.0-31-generic #31~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Aug 16 13:45:26 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Scope
Running tests with native test runner
Module and version
Not applicable.