2017-05-09 4 views
0

Reagieren Mit + Enzym + Jest<element> .innerText im Code der Komponentenmethode funktioniert beim Testen von Enzymen nicht richtig. Testing reagiert Komponente mit Jest + Enzym (mount())

Hallo, habe ich .innerText Eigenschaftswert von bestimmtem Elemente zu erhalten, siehe Zeile # 5 von meinem Code:

_modifyProfileField (event) { 
    const { currentAgentProfile, agentsDatabase } = this.state; 
    const eventTarget = event.target; 
    const agentToMod = currentAgentProfile; 
    const valueToSave = event.target.innerHTML !=='<br>' 
     ? eventTarget.innerText 
     : ''; 

    if (agentToMod[eventTarget.id] !== valueToSave) { 
     const style = eventTarget.id === 'name' 
      ? Styles.nameSaving 
      : Styles.saving; 

     eventTarget.classList.add(style); 
     const hideSaver = setTimeout(() => { 
      eventTarget.classList.remove(style); 
      clearTimeout(hideSaver); 
     }, 300); 

     agentToMod[eventTarget.id] = valueToSave; 

     const newData = agentsDatabase.map((agent) => { 
      return agent.id === agentToMod.id 
       ? agentToMod 
       : agent; 
     }); 

     this.setState({ 
      agentsDatabase:  newData, 
      currentAgentProfile: agentToMod 
     }); 

     document.activeElement.blur(); 
     window.getSelection().removeAllRanges(); 
    } 
} 

Wenn ich versuche, diese Methode zum Testen in Enzym auszuführen, gibt event.target.innerHTML zurück. Das Ändern von innerText in innerHTML ist aufgrund von Projektanforderungen nicht akzeptabel. Ist es möglich, dass Enzyme aus meinem Code innerText verstehen?

Hier ist mein Enzym Code:

expect(result 
    .state() 
    .currentAgentProfile.Country) 
    .toBe(country); 

for (const location of locations) { 
    result.find('#Country').node.innerHTML = location.city; 

    expect(result.find('#Country').text()).toBe(location.city); 

    result.find('#Country').simulate('keydown', { key: 'Enter', keyCode: 13, which: 13 }); 

    result.find('#Country').simulate('blur'); 

    expect(result 
     .state() 
     .currentAgentProfile.Country) 
     .toBe(location.city); 
} 

Die blur() Simulation löst meine Methode.

Antwort

Verwandte Themen