Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find child even though child was rendered #1197

Closed
dschinkel opened this issue Sep 29, 2017 · 4 comments
Closed

Can't find child even though child was rendered #1197

dschinkel opened this issue Sep 29, 2017 · 4 comments

Comments

@dschinkel
Copy link

dschinkel commented Sep 29, 2017

this one is really odd. Here is a screencast of it: https://youtu.be/WyfVGls69ws

but basically I find that the <title /> is indeed returned in the container's render yet the mount find isn't finding it per my css feature marker.

    it.only('renders a helmet tag for seo', () => {
      const liveScreen = mount(
        <Provider store={createStore(reducers, { live: { panels, seo: { title: "Test Title" } } })}>
          <Live
            breakpoint="site-web"
            setOverlay={() => ''}
            overlay=""
            geoLocationDeclined
            renderInfoInDetail={() => {}}
            getUseUtagGlobal={() => {}}
            pageViewEvent={() => {}}
            AccessEnablerUrl=""
          />
        </Provider>);

        const tag = liveScreen.find('.ft-seo-tag-title');

      expect(tag).to.have.length(1);
    });

the container is wrapped in a ReactTimeout HOC but I don't think that matters

const TimeoutLive = ReactTimeout(connect(mapStateToProps, {
  fetchLive,
  fetchLivePanel,
  fetchLiveVideo,
  clearLive,
  saveLiveRestart,
})(Live));

I end up with tag having length 0.

When I do a .debug() on the container, I don't see it so I guess it's not being render, which is weird, as you see in the vid it was. I will investigate unless anyone has thoughts on it...

I think what might be happening is the helmet lib is swallowing that render and rendering it in its own HOC form, because here is what I see from debug. Notice the title of Test Title is there:

<HelmetWrapper defer={true} encodeSpecialCharacters={true}>
                <SideEffect(NullComponent) defer={true} encodeSpecialCharacters={true} title="Test Title" titleAttributes={{...}}>
                  <NullComponent defer={true} encodeSpecialCharacters={true} title="Test Title" titleAttributes={{...}} />
                </SideEffect(NullComponent)>
              </HelmetWrapper>

Update #1

well this is weird, I put a marker on the helmet tag and it still can't find it:

const title = liveScreen.find('.ft-seo-tag')

<HelmetWrapper className="ft-seo-tag" defer={true} encodeSpecialCharacters={true}>
                <SideEffect(NullComponent) className="ft-seo-tag" defer={true} encodeSpecialCharacters={true} title="Test Title" titleAttributes={{...}}>
                  <NullComponent className="ft-seo-tag" defer={true} encodeSpecialCharacters={true} title="Test Title" titleAttributes={{...}} />
                </SideEffect(NullComponent)>
              </HelmetWrapper>

ends up in length of zero even though clearly the className is there when looking at the enzyme output!

Update #2

Ok I don't like doing finds on Component names because that couples my tests to implementation details but for the sake of debugging this, I did:

const title = liveScreen.find(Helmet)

What's interesting or weird is that it finds it when going the find by Component route.

But then that still begs the question of my original problem, if that's the case why didn't my find on the marker work if you can clearly see it as a prop below when I find it by Component Name?

screen shot 2017-09-29 at 11 34 58 am

So this is mounted, I'd figure that it should be able to find anywhere in the react tree, through any HOC levels in order to find my marker, without having to do anything other than mount()...is that correct?:

screen shot 2017-09-29 at 11 43 12 am

when I try this, it's not finding it and I don't know why:

screen shot 2017-09-29 at 11 37 41 am

Update #3

Just fiddling around with stuff. This is weird too. So if I try this route just for the hell of it, I'm able to get at the child of the HOC that has what I'm actually trying to test:

screen shot 2017-09-29 at 12 08 17 pm

When we just look at props you see:

screen shot 2017-09-29 at 12 17 04 pm

So I said fine, it's weird how helmut's structure is, not intuitive but thought ok, lets see if I can get the title by doing const title = tag.props().children[0].props().children since you see there that children is a property and contains the title I'm testing:

screen shot 2017-09-29 at 12 10 51 pm

hmm why would that be an error?

If I take one step back, it's saying I can't call props() on that child when it does have props?

screen shot 2017-09-29 at 12 15 15 pm

@dschinkel dschinkel changed the title Can't find child even though rendered Can't find child even though child was rendered Sep 29, 2017
@dschinkel
Copy link
Author

resolved but was kinda nasty. @ljharb any ideas to improve on this?

solution: expect(title.children[0][0].props.children).to.equal(data.live.seo.title);

screencast: https://youtu.be/tnPWcb-55b4

@ljharb
Copy link
Member

ljharb commented Oct 2, 2017

title.childAt(0).prop('children') doesn't work?

You should never need bracket access on an enzyme wrapper.

@dschinkel
Copy link
Author

well usually I bypass having to do any traversing like that by adding css feature markers but yea. I'll try that although doing children[0].prop('children') didn't work. I had to access it via multidimensional array due to the fact that for some reason I couldn't find by feature marker this time.

@3axap4eHko
Copy link

#1233 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants