2017-08-03 38 views
1

這裏是我的組件:Vue的單元測試 - 的textContent不包含預期propsData

<template> 
    <div> 
    {{serviceConfig.name}} 
    </div> 
</template> 

<script> 
export default { 
    props: ['serviceConfig'] 
} 
</script> 

在我的測試,我設置serviceConfig這樣的:

it(`should render serviceConfig`,() => { 
    const Constructor = Vue.extend(TestMe2); 
    const comp = new Constructor({ 
     propsData: { 
      serviceConfig: '{ "name": "Apple" }' 
     } 
    }).$mount(); 

    expect(comp.serviceConfig).to.equal('{ "name": "Apple" }'); // successfull 
    expect(comp.$el.textContent).to.contain('Apple'); // unsuccessfull 

}); 

但是,如果我改變我這樣我就可以渲染{{serviceConfig}}而不是serviceConfig.name,它可以工作,但不是我想要的(因爲我只是想要名稱,即'Apple')。

回答

2

您正在傳遞一個字符串,而不是對象,如serviceConfig

+0

duh ............ – Infodayne