Unit-testing Electron-React app with Jest


#1

Implementing jest snapshot tests in an electron-react app i run into an error:

TypeError: Cannot match against ‘undefined’ or ‘null’.

I can’t find any way to get the tests working when a React component contains electron navite elements such as shell, Menu, MenuItem.

I have tried passing shell as a prop, as in the commented code in Home.spec.js, but there is no change.

Home.js

import React, { Component } from 'react';
import { remote } from 'electron';
const { shell } = remote;

export default class Home extends Component {
    openLink() {
        shell.openExternal('https://www.facebook.com')
    }

    render() {
        return (
            <div>
                <button onClick={() => this.openLink()}>
                    Open External
                </button>
            </div>
        )
    }
}

Home.spec.js

import React from 'react';
import renderer from 'react-test-renderer';

import Home from '../../app/components/Home';

// import { remote } from 'electron'
// const { shell } = remote;

describe('Counter component', () => {
    it('should render snapshot', () => {
        const component = renderer.create(
            <Home />
            //<Home shell={shell} />
        )
        const tree = component.toJSON()
        expect(tree).toMatchSnapshot()
    })
});

#2

I have the same problem, nobody an idea how to handle this ?