score:0

add a wrapper

(function (factory) {
    if (typeof module === 'object' && module.exports) {
        module.exports = factory();
    } else {
        factory()();
    }
}(function() {
    // you code
    return function () {}
        
}));

score:1

an iife will always run when the file gets imported.

you can mock the entire file so it never runs, but then you can't access the functions defined in it.

there isn't a way to mock just the iife while still being able to access the other functions defined in the same file since anything that imports the code (including jest.requireactual) will also run the iife.

sounds like the two options you have are to set up your testing environment so that the iife doesn't throw an error when it runs, or move the functions to their own module so you can import and test them independently from the iife.


Related Query

More Query from same tag