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.

1
  • 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) Commented Jun 18, 2020 at 17:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.