2016-03-01 66 views
0

陣營分量I保持收到這個錯誤而測試反應組分:錯誤而測試使用茉莉

Error: Invariant Violation: findComponentRoot(..., .0): Unable to find element. This probably means the DOM was unexpectedly mutated (e.g., by the browser), usually due to forgetting a <tbody> when using tables, nesting tags like <form>, <p>, or <a>, or using non-SVG elements in an <svg> parent. Try inspecting the child nodes of the element with React ID ``.

碼I用於測試:

describe(`Method: flattenData`,() => { 

    const tests = [ 
    { 
     toFlatten: { 
     'key1': 'k', 
     'key2': 'n', 
     'key3': 'o' 
     }, 
     expectedResult: 'key1: k; key2: n; key3: o' 
    } 
    ]; 

    tests.forEach((test) => { 

    expect(instance.flattenData(test.toFlatten)).toEqual(test.expectedResult); 

    }); 

}); 
+0

你能提供有關'instance'更多信息變量是否引用?調用'instance.flattenData'或創建組件實例時發生錯誤 –

+0

我找到了修復程序,我沒有提供有關錯誤實例的更多數據以及實例。 flattenData在這種情況下不相關無論如何。 –

回答

0

我通過添加一個參數到固定的這個錯誤渲染調用。這迫使部分(這僅僅是一個表裏面呈現一個<td> </td>

前:

[container, instance] = render(TableCell, { 
    data: `content`, 
    dataTh: `content`, 
    key: `content`, 
    dataLocator: `content` 
}); 

隨着修復:

[container, instance] = render(TableCell, { 
    data: `content`, 
    dataTh: `content`, 
    key: `content`, 
    dataLocator: `content` 
}, `table`);