簡體   English   中英

酶-Mount無法通過ID查找元素

[英]Enzyme - Mount can't find element by id

我構造包裝器:

this.wrapper = mount(<App />, { context: this.store });

然后,我嘗試通過其ID查找某個HTML元素:

console.log("WRAPPER:", this.wrapper.debug());
return this.wrapper.find('#Form-input[0]-fields-field1');

包裝器找不到此元素。 console.log的輸出如下:

WRAPPER:
<Many children/components down...>
    <input name="Form-input[0].fields.field1" onBlur={[Function]} onChange={[Function]} onDragStart={[Function]} onDrop={[Function]} onFocus={[Function]} value="asdf" type="text" id="Form-input[0]-fields-field1" disabled={false} />
<Many more things after this...>

因此,肯定有正確ID的輸入。 我想念什么嗎?

看來您使用的是ID選擇器#Form-input[0]-fields-field1但我認為[]CSS ID無效,也許您可​​以按名稱搜索輸入, input[name="Form-input[0]-fields-field1"]工作嗎? 如果我錯了,並且方括號實際上是可以的,那么您可能仍需要在查詢中轉義它們!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM