I use init-native init to create a reaction project. I am using the https://github.com/andpor/react-native-sqlite-storage library for SQLite bindings.
I have a test file DbConnector.jest-test.js. Content
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 run jest, I get the following error, even if by default node_modules are ignored.
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
Import to DbConnector.js looks like this:
import React, { Component } from 'react' import { AppRegistry, StyleSheet, Text, View, TextInput, Button, Alert, AsyncStorage } from 'react-native' import SQLite from 'react-native-sqlite-storage'
source share