2

I've a simple spec file to run JEST:

describe('config', () => {
  it('should be able to open database', () => {
    console.log(SQLite);
    SQLite.openDatabase(
      {
        name: 'TestDB',
        createFromLocation: '~/www/test.db'
      },
      () => console.log('success'),
      () => console.log('fail')
    );
  });
});

I want to write test which can open a pre-populated test.db (created using DB Browser for SQlite). DB is within ./www/test.db relative to the location of spec file. When I run SQLite.openDatabase, it fails with following error:

TypeError: Cannot read property 'open' of undefined

Eventually, I want to write a library to access data from sqlite as needed by a react-native app. However, this is the basic test which blocks further work.

helloworld
  • 2,179
  • 3
  • 24
  • 39
  • Just to update my question, I couldn't find any way to do so. Eventually, I opted for custom mocks which imitate JEST functionality a lot. I can also use json files or real sqlite database using sqlitedb library (which works fine in opening database) – helloworld Jun 18 '20 at 17:06

0 Answers0