简体   繁体   中英

Enzyme - Mount can't find element by id

I construct the wrapper:

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

Then I try to find a certain HTML element by its id:

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

The wrapper is unable to find this element. The output of the console.log is as follows:

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...>

So the input with the correct id is definitely there. Am I missing something?

It appears that you are using an ID selector #Form-input[0]-fields-field1 but I believe that [ and ] are invalid for CSS IDs , perhaps you could search for the input by name, does input[name="Form-input[0]-fields-field1"] work? And if I am wrong and the square brackets are in fact OK, you may still need to escape them in the query!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM