How would I do component testing if my component requires access to a database

I created an electron app which persists data in NeDB which displays data through the app. I’m trying to test my component which displays the data with jest and enzyme, but my simple test fails because one of my module that is imported to the file requires access to a property that is only defined when I run the electron app.

I’m new to creating electron app so my architecture might be bad.

The main issue is when I try to run my test I get the error,

 TypeError: Cannot read property 'app' of undefined    1 | const remote = require('electron').remote; > 2 | const app = remote.app; 

How would I go about fixing this? Some possible things I thought might work was to use jest to mock SchoolAPI, but I’m not sure how to go about doing this.

SchoolList.js

import React from "react"; // @material-ui/core components import withStyles from "@material-ui/core/styles/withStyles"; import List from "@material-ui/core/List"; import ListItem from "@material-ui/core/ListItem"; import ListItemText from "@material-ui/core/ListItemText"; import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction'; import IconButton from '@material-ui/core/IconButton'; import DeleteIcon from '@material-ui/icons/Delete';  import { Link } from "react-router-dom";  import * as SchoolAPI from "../../utils/SchoolAPI.js"  class SchoolList extends React.Component {     constructor(props) {         super(props);     };      handleDelete = (id) => {         SchoolAPI.deleteSchool(id).then(() => {             this.props.onLoadData();         });     };     render() {         const { classes } = this.props;         const listSchools = this.props.schoolsData.map((school, i) =>             <div key={i}>                 <ListItem button component={Link} to={`/orders/$  {i}`}>                     <ListItemText primary={school.name}/>                     <ListItemSecondaryAction onClick={() => this.handleDelete(school["_id"])}>                         <IconButton aria-label="Delete" >                             <DeleteIcon />                         </IconButton>                     </ListItemSecondaryAction>                 </ListItem>             </div>         );         return (             <List className="schoolList">                 {listSchools}             </List>         );     }; } 

SchoolAPI.js

import db from "../db.js" ...a bunch of API(e.g. db.insert(..)) 

db.js

const remote = require('electron').remote; const app = remote.app; const path = require('path'); const Datastore = require('nedb-promises');  const dbFactory = (fileName) => Datastore.create({   filename: `$  {process.env.NODE_ENV === 'dev' ? '.' : app.getPath('userData')}/data/$  {fileName}`,    timestampData: true,   autoload: true });  const db = {   schools: dbFactory('schools.db') };  module.exports = db; 

test.spec.js

describe("SchoolList component", () => {     it("renders without throwing an error", () => {         const SchoolListComponent = renderer.create(<SchoolList schoolsData={schoolsData/>).toJson();         expect(SchoolListComponent).toMatchSnapshot();     }); });