How to use dialog electron with Theia

Hello,

I have this React code :

import { dialog } from '@electron/remote';

//..some code..

        dialog
            .showOpenDialog({
                properties: ['openFile'],
                filters: [{ name: 'files', extensions: ['pdf'] }],
            })
            .then(files => {
                      //doSomething();
            })

This code works fine but when I test a parent component using mocha and chai, the test fails with this error : No such module was linked: electron_common_features .

I replaced the import of dialog as below, the test passes, but the dialog doesn’t work anymore, and shows this message error : Cannot read properties of undefined (reading ‘showOpenDialog’).

import { dialog } from '@theia/core/electron-shared/electron';

I need to know the right way to use dialog electron with Theia that makes my test passes and my app works.
Thanks.

@MJ thank you for the discussion, are you writing unit tests or integration tests? I may be wrong but I do not believe it is possible to test electron with mocha and chai without mocking electron in your tests.

Thanks @vince-fugnitto , yes I am writing unit tests.
I am not testing electron itself, but I am trying to test some feature in a react component that has a child that happens to import the “dialog”; this latter that I am not trying to test raises an error in test like I first described.

@MJ I don’t think it is possible to test as a unit-test without mocking electron itself for your tests.