Hello @arpanaarora.934 and fellow test architects! Adding another perspective to your challenge with Cypress spies on imported functions, and building on the workarounds discussed.
I’ve had this exact same issue myself! Importing a helper function used across components and trying to spy on it from Cypress simply didn’t work out of the box.
You’re right: Cypress can’t magically overwrite imports in a running app’s built bundle.
The workaround that helped me involved mocking the module before the app was bundled, typically by using a custom test build with injected spies (via Jest or a Babel plugin), and then exposing what I needed globally.
It was, however, kind of brittle to maintain. Honestly, for shared logic like that, I’ve found it’s often better to write precise unit tests with Jest and then reserve Cypress to verify the broader behavior through UI side effects.
Hope this experience, and the strategic distinction between testing levels, helps you refine your approach!