I am using react-native init to create a react-native project. I am using https://github.com/andpor/react-native-sqlite-storage library for SQLite bindings.
I have a DbConnector.jest-test.js unit tests file. Contents are
import DbConnector from '../app/components/DbConnector.js';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
it('renders correctly', () => {
const tree = renderer.create(
<DbConnector />
);
});
When I am running jest, I am getting following error even if by default node_modules are ignored. I am using react-native preset in package.json
Test suite failed to run
ReferenceError: window is not defined
at Object.<anonymous> (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:53:10)
at Object.<anonymous> (node_modules/react-native-sqlite-storage/sqlite.js:10:12)
at Object.<anonymous> (app/components/DbConnector.js:3:31)
Test Suites: 1 failed, 1 total
Imports in DbConnector.js are as:
import React, { Component } from 'react'
import { AppRegistry, StyleSheet, Text, View, TextInput, Button, Alert,
AsyncStorage } from 'react-native'
import SQLite from 'react-native-sqlite-storage'
You should try to mock react-native-sqlite-storage before your test.
jest.mock('react-native-sqlite-storage');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With