Enzyme: UNSAFE_ methods are not called with shallow

Created on 25 Jun 2018  路  9Comments  路  Source: enzymejs/enzyme

Describe the bug
It seems shallow mounted components don't call UNSAFE_componentWillReceiveProps (and probably other methods)

To Reproduce
Steps to reproduce the behavior:

  1. Create a working test that relies on componentWillReceiveProps
  2. rename the method to UNSAFE_componentWillReceiveProps
  3. test now fails

Expected behavior
Since these are aliases, they should work the same.

All 9 comments

related: #1602 #1600

I've written these tests, and they pass on master.

I am still experiencing this issue using the latest versions of enzyme and enzyme-adapter-react-16. I am using the shallow renderer. Workarounds are to revert back to the deprecated componentWillReceiveProps or use mount.

@jayfunk I'm about to release v3.4.4; once that's out, if you still have an issue, it'd be great if you could file a new issue.

Tried to recreate the issue outside of my project and I have not been able to. My test did not include karma as it does in my project where shallow is not working as expected. Might be something related to that setup that is causing the failure. Ill circle back on this to see if I can recreate it with a controlled test.

Any update on this issue? I am running into the exact same issue @jayfunk described on 8/20. Spinning up an example site now but any update would be much appreciated!

As far as i know, it鈥檚 fixed. If you have a repro case, please do file a new issue.

For those chasing this down my issue was that we were running react-test-renderer 16.2 instead of 16.6, and as the lifecycle methods were updated in release 16.3 it was breaking our tests.

Credit to Github user audiolion for pointing this out in the thread for another issue:

https://github.com/airbnb/enzyme/issues/1600#issuecomment-384113704

Definitely all your react packages need to be identical versions, or at least the same minor.

You can verify your dep tree with npm ls as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abe903 picture abe903  路  3Comments

potapovDim picture potapovDim  路  3Comments

blainekasten picture blainekasten  路  3Comments

benadamstyles picture benadamstyles  路  3Comments

AdamYahid picture AdamYahid  路  3Comments