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

shallow lifecycleExperimental not works in react native #1279

Closed
jose920405 opened this issue Oct 18, 2017 · 9 comments
Closed

shallow lifecycleExperimental not works in react native #1279

jose920405 opened this issue Oct 18, 2017 · 9 comments

Comments

@jose920405
Copy link

jose920405 commented Oct 18, 2017

Based on this documentation

Example code:

In my test file:

shallow(
    <LoginScreen />,
    { context: { store }, lifecycleExperimental: true },
  );

In my component:

class LoginScreen extends Component {

  constructor(props) {
    super(props)
  }

  componentDidMount() {
    console.log('componentDidMount ===>')  // This log is never fired
  }

  componentDidUpdate() {
    console.log('componentDidUpdate ====> ') // This log is never fired
  }

  render() {
    console.log('Inside component Render') // This log is fired
    return (
      <View style={styles.mainContainer}>
      </View>
    )
  }
}

I have also tried with disableLifecycleMethods: false but either works

captura de pantalla 2017-10-18 a la s 3 15 00 p m

@jose920405 jose920405 changed the title lifecycleExperimental not works in react native shallow lifecycleExperimental not works in react native Oct 18, 2017
@ljharb
Copy link
Member

ljharb commented Oct 18, 2017

What version of enzyme are you using? v3 doesn't have lifecycleExperimental anymore; it's on my default.

@jose920405
Copy link
Author

hi @ljharb

My version is 2.9.1.

captura de pantalla 2017-10-18 a la s 4 33 57 p m

@jose920405
Copy link
Author

My react info:

"react": "16.0.0-alpha.12",
"react-native": "0.47.2",

I just realized that there are problems with version 16 alpha of react. This is the reason for the problem I am having

@ljharb
Copy link
Member

ljharb commented Oct 20, 2017

@jose920405 since react v16 is out, can you try that?

@jose920405
Copy link
Author

ok. i'll try and i supose that is necessary use enzyme-adapter-react-16 so i will instal it too.

@jose920405
Copy link
Author

@ljharb

Yeah, update my react version to 16.0.0 and use enzyme-adapter-react-16 fix my problems. Thanks

@jose920405
Copy link
Author

jose920405 commented Oct 23, 2017

hi @ljharb,

I'm testing a lot more thoroughly and I can see that componentDidUpdate() is not running. Is there a rule for this?

The render runs correctly each time, but the componentDidUpdate does not. I'm clear that I'm not doing anything special to try to get this to run, I'm just triggering a press and letting my code work on its own

const buttons = render.find('TouchableOpacity');
const loginButton = buttons.first()
loginButton.simulate('press')

PDTA: componentDidMount Works

@jose920405
Copy link
Author

jose920405 commented Oct 23, 2017

I upgraded to version: `3.1.0`

@ljharb

I am testing and apparently this is a problem related to redux interactions. When I change my redux dispatch by a simple setState, componentDidUpdate is executed correctly

@ljharb
Copy link
Member

ljharb commented Jul 6, 2018

You'd need a react native adapter to use enzyme with React Native.

Closing this in favor of #1436.

@ljharb ljharb closed this as completed Jul 6, 2018
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

2 participants