2017-07-25 9 views
5

मैं प्रतिक्रिया-मूल परियोजना बनाने के लिए प्रतिक्रिया-मूल init का उपयोग कर रहा हूं। मैं SQLite बाइंडिंग के लिए https://github.com/andpor/react-native-sqlite-storage लाइब्रेरी का उपयोग कर रहा हूं।बाहरी प्लगइन का उपयोग कर प्रतिक्रिया-मूल में जेस्ट टेस्ट केस त्रुटि

मेरे पास एक 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 /> 
); 
}); 

हैं जब मैं हंसी चला रहा हूँ, मैं निम्न त्रुटि भले ही डिफ़ॉल्ट रूप से node_modules अनदेखी कर रहे हैं हो रही है। मैं 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 

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' 

उत्तर

3

लगता window is not defined आपकी समस्या की तरह इस लाइन से आ रही है: https://github.com/andpor/react-native-sqlite-storage/blob/master/lib/sqlite.core.js#L53

यह ऐसा लगता है कि आपके परीक्षण में react-native का आयात गुम है और इसे इस तरह दिखना चाहिए:

import 'react-native'; 
import renderer from 'react-test-renderer'; 

यदि वह काम नहीं करता, तो आप JSDOMfrom this guide प्रयोग करने के लिए निम्न चरणों का पालन करने के लिए सक्षम हो सकता है (जो एंजाइम से है, लेकिन अभी भी मदद कर सकता है!)

1

आप से पहले प्रतिक्रिया देशी-SQLite भंडारण उपहास करने के लिए प्रयास करना चाहिए आपका परीक्षण

jest.mock('react-native-sqlite-storage'); 
संबंधित मुद्दे