How do I access the 'remote' module or other main process modules from my unit tests? I'm getting Error: Cannot find module 'remote'
when testing a component that depends on 'remote'. I've also looked into mocking it but am not sure how to handle that, any guidance would be much appreciated.
So I didn't find a perfect answer in my search but I ended up just using mockery to mock the remote
module. I also looked into electron-mocha but could never get it working though the readme leads me to believe it solves the issue I was having. If anyone has experience unit testing Electron apps that use React please post up a better solution!
Accessing the remote module from your unit tests simply requires your tests to be running in the right context. To be specific, this would be in a Renderer process. You can do this by running your tests in a BrowserWindow.
It is likely that you'll want a more integrated workflow. For this electron-mocha has worked for me. Using it I split my tests into four separate tasks covering the different contexts I felt relevant:
They have to be run independently and the start up time of electron is slower than you may be used to when using node.
Finding an answer to the mocking aspect of your question is why I'm here, but I'm expecting it to be the same as mocking any javascript object. I'll try and add to/edit this if I find a more specific solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With