我在后端使用Meteor,在前端使用React .

Follow Component只从MongoCollection TestCollection中获取每个Element,并使用名为ListElement的Component显示数据 . 每次收集更新时,我都使用包 TrackerReact 来更新我的列表组件

export default class List extends TrackerReact(Component){

 displayCollection(){
     return TestCollection.find({}).fetch().map((element)=>
         <ListElement key={element._id} name={element.name} />
   );
 }

 render(){
        <div className="main">
            {displayCollection()}
        </div>

  }

}

接下来,我想通过将测试数据添加到集合中并使用Enzyme检查ListElements是否已添加到我的列表来测试Component

describe('<List />', () => {
 it('Test', () => {
   const wrapper = mount(<List>);
   // check component content
   expect(wrapper.find("div.main")).to.have.length(1);

   // insert dummy date to Collection
   StubCollections.add([TestCollection]);
   StubCollections.stub();
   TestCollection.insert({name:" marko"});
   expect(TestCollection.find().count()).to.equal(1);

   //Test Output
   console.log(wrapper.find("div.main").text());
   console.log(wrapper.find("div.main").html());
   });

});

我遇到的问题是,我的测试输出显示text()函数没有值,而html()只返回:

<div className="main"> </div>

我该如何正确测试?