2017-05-17 8 views
6

मैं स्थानीय भंडारण में स्टोर करने के लिए universal-cookie का उपयोग कर रहा हूं, जिसे स्टोर में पाइप किया जाता है।"धूम्रपान हेडर या ऑब्जेक्ट गुम है" प्रतिक्रिया धुएं के परीक्षणों के दौरान फेंक दिया गया त्रुटि (बनाएँ-प्रतिक्रिया-ऐप)

class App extends Component { 

    componentDidMount() { 
    // if a cookie is present, save the value in the store for use communication 
    // with the server. If the cookie is undefined, the user is redirected to the login page. 
    // Redirection is handled by router. 
    const userNameInCookie = cookies.get('userName'); 
    if (userNameInCookie) { 
     this.props.dispatch(actions.setUserNameFromCookie(userNameInCookie)); 
    } 
    } 

    render() { 
    return (
     <div> 
      <div className="header"> 
       <h2 className="header-title">Traveler</h2> 
      </div> 
      {this.props.children} 
     </div> 
    ); 
    } 
} 

जब मैं जेस्ट टेस्ट स्वीट चलाने के लिए, हर एक परीक्षण इस त्रुटि

FAIL src/test/UserCreateForm.test.js 
● Test suite failed to run 

Missing the cookie header or object 

    at new Cookies (node_modules/universal-cookie/lib/Cookies.js:35:15) 
    at Object.<anonymous> (src/actions/index.js:4:17) 
    at Object.<anonymous> (src/reducers/index.js:1:258) 
    at Object.<anonymous> (src/store.js:4:40) 
    at Object.<anonymous> (src/test/UserCreateForm.test.js:7:40) 
    at handle (node_modules/worker-farm/lib/child/index.js:41:8) 
    at process.<anonymous> (node_modules/worker-farm/lib/child/index.js:47:3) 
    at emitTwo (events.js:106:13) 
    at process.emit (events.js:194:7) 
    at process.nextTick (internal/child_process.js:766:12) 
    at _combinedTickCallback (internal/process/next_tick.js:73:7) 
    at process._tickCallback (internal/process/next_tick.js:104:9) 

मैं भी एनजाइम साथ धूम्रपान परीक्षण की कोशिश की है के साथ विफल रहता है, लेकिन मैं एक ही त्रुटि मिलती है। कोड ठीक वैसे ही व्यवहार कर रहा है जैसा मैं चाहता हूं, इसलिए मुझे विश्वास है कि universal-cookie बस परीक्षणों के साथ नहीं मिल रहा है।

कोई विचार? धन्यवाद!

उत्तर

0

क्या आपने सार्वभौमिक कुकी आयात की है और फिर कक्षा को परिभाषित किया है?

import Cookies from 'universal-cookie'; 
const cookies = new Cookies(); 

तो अपने कोड प्रतीत होता ...

import Cookies from 'universal-cookie'; 

class App extends Component { 
    componentDidMount() { 
    const cookies = new Cookies(); 
    const userNameInCookie = cookies.get('userName'); 
    if (userNameInCookie) { 
     this.props.dispatch(actions.setUserNameFromCookie(userNameInCookie)); 
    } 
    } 

    render() { 
    return (
     <div> 
     <div className="header"> 
      <h2 className="header-title">Traveler</h2> 
     </div> 
     {this.props.children} 
     </div> 
    ); 
    } 
} 
संबंधित मुद्दे