【发布时间】:2017-07-25 06:53:33
【问题描述】:
我正在使用 react-native init 创建一个 react-native 项目。我正在使用https://github.com/andpor/react-native-sqlite-storage 库进行 SQLite 绑定。
我有一个 DbConnector.jest-test.js 单元测试文件。内容是
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 />
);
});
当我运行 jest 时,即使默认 node_modules 被忽略,我也会收到以下错误。我在 package.json 中使用 react-native 预设
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
DbConnector.js 中的导入如下:
import React, { Component } from 'react'
import { AppRegistry, StyleSheet, Text, View, TextInput, Button, Alert,
AsyncStorage } from 'react-native'
import SQLite from 'react-native-sqlite-storage'
【问题讨论】:
标签: javascript android sqlite react-native jestjs