2017-10-08 15 views
9

कल मैं उन्नत बनाया मेरी v16.0 के लिए परियोजना प्रतिक्रिया है, लेकिन मैंने पाया कि एनजाइम कुछ समस्याओंएंजाइम सेटअप फ़ाइल कहां लिखा जाना चाहिए?

Error: 
     Enzyme Internal Error: Enzyme expects an adapter to be configured, but found none. To 
     configure an adapter, you should call `Enzyme.configure({ adapter: new Adapter() })` 
     before using any of Enzyme's top level APIs, where `Adapter` is the adapter 
     corresponding to the library currently being tested. For example: 
     import Adapter from 'enzyme-adapter-react-15'; 
     To find out more about this, see http://airbnb.io/enzyme/docs/installation/index.html 

    at validateAdapter (spec/components/page_components/SongListItem/index.spec.js:9:1141986) 
    at getAdapter (spec/components/page_components/SongListItem/index.spec.js:9:323041) 
    at new ReactWrapper (spec/components/page_components/SongListItem/index.spec.js:9:622193) 
    at mount (spec/components/page_components/SongListItem/index.spec.js:9:2025476) 
    at UserContext.<anonymous> (spec/components/page_components/SongListItem/index.spec.js:9:1235741) 

था और मैं आधिकारिक website

// setup file 
import { configure } from 'enzyme'; 
import Adapter from 'enzyme-adapter-react-16'; 

configure({ adapter: new Adapter() }); 

पर एक समाधान पाया लेकिन मैं एक समस्या है: एंजाइम सेटअप फ़ाइल कहाँ लिखा जाना चाहिए? प्रत्येक परीक्षण फ़ाइल के सामने?

मैं परीक्षण फ़ाइलों में से एक करने के लिए ऊपर दिए गए कोड जोड़ने की कोशिश की, लेकिन वहां अभी भी एक समस्या

Internal error: attempt to prepend statements in disallowed (non-array) context at C:/Users/killer/workspace/react/NetEase-Cloud-Music-Web/spec/components/page_components/SongListItem/index.spec.js 

This

उत्तर

21

मैं एक ऐसी ही समस्या हुई अपने प्रोजेक्ट का पता है है

यदि आप अपने परीक्षण चलाने के लिए जेस्ट का उपयोग कर रहे हैं, तो आप test-setup.js फ़ाइल बना सकते हैं और एंजाइम दस्तावेज़ों से स्निपेट जोड़ सकते हैं:

// test-setup.js 
import { configure } from 'enzyme'; 
import Adapter from 'enzyme-adapter-react-16'; 

configure({ adapter: new Adapter() }); 

फिर अपनी जेस्ट कॉन्फ़िगरेशन में setupTestFrameworkScriptFile कुंजी जोड़ें और उस फ़ाइल को इंगित करें। उदाहरण के लिए, अपने हंसी विन्यास package.json में है अगर:

// package.json 
{ 
    ..., 
    "jest": { 
     "setupTestFrameworkScriptFile": "<rootDir>/test-setup.js" 
    } 
} 
हंसी डॉक्स https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string से

:

एक मॉड्यूल के लिए पथ कॉन्फ़िगर या प्रत्येक से पहले परीक्षण ढांचे की स्थापना के लिए कुछ कोड चलाता है परीक्षा। चूंकि setupFiles पर्यावरण में परीक्षण ढांचे को स्थापित करने से पहले निष्पादित करता है, इसलिए यह स्क्रिप्ट फ़ाइल आपको पर्यावरण में परीक्षण ढांचे को स्थापित करने के तुरंत बाद कुछ कोड चलाने का अवसर प्रस्तुत करती है। अपने हंसी पर्यावरण initialised होने के बाद

इस पर अमल होगा, लेकिन आपके एंजाइम परीक्षणों

3

क्रियान्वित कर रहे हैं से पहले अपने सेटअप फ़ाइल के लिए बनाने प्रतिक्रिया-ऐप, उम्मीद पथ का उपयोग कर लोगों के लिए src/setupTests.js है।

शुरु कर रहा है टेस्ट पर्यावरण

नोट:: documentation (README) GitHub पर देखें इस सुविधा [email protected] और उच्च के साथ उपलब्ध है। यदि आपका ऐप एक ब्राउज़र एपीआई का उपयोग करता है जिसे आपको अपने परीक्षणों में नकल करने की आवश्यकता है या यदि आपको अपने परीक्षण चलाने से पहले वैश्विक सेटअप की आवश्यकता है, तो अपनी परियोजना में src/setupTests.js जोड़ें। अपने परीक्षण चलाने से पहले इसे स्वचालित रूप से निष्पादित किया जाएगा।

(के रूप में बनाने के प्रतिक्रिया एप्लिकेशन के अंतर्गत प्रबंधन नहीं करती है, कम से कम v1.4.1 में, विकल्प setupTestFrameworkScriptFile package.json में)।

संबंधित मुद्दे