Tôi đang sử dụng init gốc tự do để tạo dự án phản ứng gốc. Tôi đang sử dụng thư viện https://github.com/andpor/react-native-sqlite-storage cho các liên kết SQLite.Lỗi trường hợp thử nghiệm Jest trong phản ứng gốc bằng cách sử dụng plugin bên ngoài
Tôi có tệp kiểm tra đơn vị DbConnector.jest-test.js. Nội dung là
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 />
);
});
Khi tôi chạy jest, tôi nhận được lỗi sau ngay cả khi mặc định node_modules bị bỏ qua. Tôi đang sử dụng cài đặt trước phản ứng bản địa trong 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
Nhập khẩu trong DbConnector.js như:
import React, { Component } from 'react'
import { AppRegistry, StyleSheet, Text, View, TextInput, Button, Alert,
AsyncStorage } from 'react-native'
import SQLite from 'react-native-sqlite-storage'