Enzyme: Can't find tags containing a dot

Created on 9 Apr 2018  路  6Comments  路  Source: enzymejs/enzyme

Current behavior

This is related to #439.

When .find()ing a component that contains a dot (.) in its name (e.g. <Some.Name />), enzyme is unable to get it.

Tried with:

component.find('Some.Name')
component.find('Some\.Name')
component.find('Some\\.Name')

But all of them return a 0-length wrapper.

Expected behavior

It should return the components that match that tag name, probably with the escaped syntax: component.find('Some\.Name').

CSS selectors apparently support the \. escaping.


Your environment

API

  • [x] shallow

Version

| library | version
| ---------------- | -------
| Enzyme | 3.2.0
| React | 16.1.1

Adapter

  • [x] enzyme-adapter-react-16

Most helpful comment

Import it, and pass the component itself onto find

All 6 comments

I just noticed that Some acts as an object there, and what is actually rendered is Name. Absolute slip, sorry for the inconvenience!

I'm running into the same issue.

Thats my snapshot

<withTheme(Appbar.Header)>
  <withTheme(Appbar.Content)
    title="Flashcards"
  />
  <Appbar.Action
    icon="search"
    onPress={[MockFunction]}
    size={24}
  />
</withTheme(Appbar.Header)>

It didn't found anything when I've tried wrapper.find('Appbar.Action') .

@YagoGG how did you solve this problem?

@brunohkbx try finding it by reference instead of with a string name.

@ljharb sorry, can you provide me an example?
thanks.

Import it, and pass the component itself onto find

Thanks @ljharb, got it :smile:

Was this page helpful?
0 / 5 - 0 ratings