2017-06-19 30 views
1

我試圖讓我的頭在開玩笑。這是我的測試:如何測試組件是否包含字符串?

test('whether contains className',() => { 

    let list = [ 
     { 
      id: 12, 
      name: 'two', 
      completed: true 
     } 
    ]; 

    const wrapper = shallow(
     <Todos todos={list}> 
     </Todos> 
    ); 

    expect(wrap).toMatch(/strikethrough/); 
}); 

如何檢查組件中是否包含(子)字符串?

回答

3

您需要使用.text()方法獲取當前渲染樹的渲染文本。

expect(wrapper.text()).toMatch(/strikethrough/) 
+0

我該如何檢查html?我有一個className值,我想檢查一下嗎? –

+0

其實,這會給html一個字符串。使用'console.log(wrapper.text())'看看你得到了什麼。 –

相關問題