Ask coding questions

← Back to all posts
unit test for node.js module

I have a node.js project and would like to unit test a function. When I run the unit test it runs the code from index.js. In my case this is a Command Line Interface program and replit errors out.

So I moved the function that I want to test to a separate module change-function.js. I import this module in the unit test, but replit still runs index.js.

Is there a way to test the exports from a module in a node.js project?