Ask coding questions

← Back to all posts
jest test for void method with side-effects

I have a JS function I want to test:

It doesn't return a value. It just has side-effects (change COLS value and size the matrix.
I export values as below:

My jest test of this function always fails. It's as if initialize() was never called.

Does REPLIT have a testing bug? Must I do some thing different in jest?

Answered by Coder100 [earned 5 cycles]
View Answer

hello, please look at this repl:

it is not a replit bug, its js behavior. The exported object doesn't get changed by the export. Try using some global variables, or make a config object.


Yes, @Coder100, you are correct. I declared the matrix as
global matrix; and now it's visible to the unit test module.

I need to learn the semantics of node's import/export mechanism better. Any ideas?


@robertrodini1 nice
2. well, just don't use it instead of global variables, and treat everything as constant.