windyGex / preact-compat-enzyme

Implement React internal properties

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When is wrapper.setProps + setTimeout needed?

oskarhane opened this issue · comments

Hi,
Thanks for this package!

I don't understand when I need to use setProps (and therefore make assertions wrapped in setTimeout).

The following code does not work, children is always empty:

const wrapper = mount(<Render if={false}><span>Hello</span></Render>)

This is needed:

    const wrapper = mount(<Render />)
    wrapper.setProps({if: false, children: <span>Hello</span>})

Could you help me understand why?

Maybe this is caused by preact. I'm not sure. And please give me a real code to debug it.

Thanks for the fast response!

You can clone git@github.com:oskarhane/neo4j-browser.git and checkout the 3.0-bring-back-enzyme branch and run yarn install and then yarn dev to test in watch mode.

The relevant test is in https://github.com/oskarhane/neo4j-browser/blob/45654bfcfc46055d7a7f8a21e63d6bfecbd007a5/src/browser/components/Render/index.test.js#L29-L56

image
Sorry, I got a error when running yarn dev

Weird. What if you try npm run dev?
You installed the dependecies?

Do you have a global old version of jest installed?

Try npm run dev got the same result. I have installed dependencies using yarn install. I'm not sure it related to node version. My node version is 6.4.0.

Hi. Thanks for this

I have the same problem. Any news about this ?

I've found that wrapper.update() after wrapper.update.setProps removes the need for async assertions.
Does that work for you too @mparpaillon?

@oskarhane Yes. Just a typo in your solution. It's

wrapper.setProps({bla: 'blabla'});
wrapper.update();

Thanks a lot :)

@windyGex This can be closed I guess

Sorry, typing on the phone :)