Skip to content
Advertisement

JavaScript/Node – Why isn’t my jest mock being called?

I am writing a unit test for a pubsub component in my service. My directory structure looks like this:

JavaScript

The file publish_to_topic.ts looks like this

JavaScript

And is called by publish_event.ts like so:

JavaScript

Lastly in my test file publish_event.test.ts, I set up a mock:

JavaScript

Alas, my test fails:

JavaScript

Can anyone explain where I’ve gone wrong? Thank you.

Advertisement

Answer

You have your mocked function wrapped in a second function (without calling the mock itself).

Update to this:

JavaScript
Advertisement