如何在柏树中测试此代码?
<Chips
id="ChipsId"
className="chips"
value={this.state.tags}
onChange={this.onChange}
suggestions={this.state.tagGroup}
fromSuggestionsOnly="true"
/>
我试过的代码是:
cy.find('#ChipsId')
.type("Freshers")
.type('{downarrow}')
.type('{enter}');
您需要使用cy.get()
而不是cy.find()
。此外,您需要以实际的<input type="text">
元素为目标,或者在使用cy.type
之前对其进行聚焦。
尝试:
cy.get('#ChipsId').click()
.focused().type('{downarrow}')
你的选择器不正确。你可以试试
cy.get("Chips[id='ChipsId']")
.type("Freshers")
.type('{downarrow}')
.type('{enter}');
此外,如果可能,请尝试添加data-*
特定于测试的属性。阅读有关此最佳实践的更多信息here
如果上述不起作用,我猜 Chips 是一个更高阶的组件对吗?意味着它包含几个其他 DOM 元素。您需要get
Chips 元素内的输入元素键入到:
cy.get("Chips[id='ChipsId']").within(() => {
cy.get('input')
.type("Freshers")
.type('{downarrow}')
.type('{enter}');
})
我现在无法测试它,但也许甚至cy.get("Chips[id='ChipsId'] input")
或cy.find("Chips[id='ChipsId'] input")
都可以工作。
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(38条)