在这些代码行之后,我可以成功访问我的包装器和实例:
containerDiv.style.width = '400px';
global.document.body.appendChild(containerDiv);
wrapper2 = mount(
<DocumentList
oid={'docOid251085'}/>,
{attachTo: containerDiv}
);
instance2 = wrapper2.component.getInstance();
wrapper = mount(
<DocumentListRow
getDocumentListWidth={instance2.getDocumentListWidth}
oid={'docOid251085'}
record={record}/>,
{attachTo: document.getElementById('DocumentGriddocOid251085')}
);
instance = wrapper.component.getInstance();
但是在下一个“it”块中,我无法访问它们,是什么让我失去了包装器和实例引用?
it("should render one row", function() {
expect(wrapper.find('Row_1_' + 'docOid251085')).to.exist;
});
it("should render one row in a card that is normal", function() {
var width;
width = instance.props.getDocumentListWidth();
expect(width).to.equal(400);
});