Search code examples
react-nativejestjsexpoexpo-sqlite

Getting an sqlite error when running tests with Jest on react-native app


I am having trouble getting tests up and running with Jest for my react-native app (expo). This is the simple test I am trying:

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

import App from '../App';

describe('<App />', () => {

  it('has 1 child', async () => {
    jest.useFakeTimers()
    const tree = await renderer.create(<App />).toJSON();
    expect(tree.children.length).toBe(1);
  });
});

And this is the error I am getting:

C:\Users\user01\github\seize-the-night\node_modules\expo-sqlite\build\SQLite.js:49
        callback(null, nativeResultSets.map(_deserializeResultSet));
                                        ^

TypeError: Cannot read properties of undefined (reading 'map')
    at C:\Users\user01\github\seize-the-night\node_modules\expo-sqlite\src\SQLite.ts:68:31
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

The app uses a expo-sqlite database. This is causing the error. I would be grateful for any help.


Solution

  • You need to mock the databas for all the DB methos that are calling to be called during the testing;

    jest.mock('../database', () => ({
              yourDBMethod: (params1, params2, callback)=>callback()
            }));