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

Feature Request: Change the prop value for a selected component #21

Closed
wing5822 opened this issue Aug 6, 2020 · 9 comments
Closed

Feature Request: Change the prop value for a selected component #21

wing5822 opened this issue Aug 6, 2020 · 9 comments

Comments

@wing5822
Copy link

wing5822 commented Aug 6, 2020

Hi there,

This is not an issue but was wondering if there was a way to change the prop values after selecting the component?

@wing5822 wing5822 closed this as completed Aug 6, 2020
@wing5822 wing5822 reopened this Aug 6, 2020
@abhinaba-ghosh
Copy link
Owner

abhinaba-ghosh commented Aug 6, 2020

Hi Thanks for raising the issue ans closing it. Can you share your anwser/analysis on this so that others can get benefitted.

Thanks.

@wing5822
Copy link
Author

wing5822 commented Aug 6, 2020

Sorry, realized that this plugin doesn't have this option so I'm going to either find a way to do it or check another plugin.

@abhinaba-ghosh
Copy link
Owner

Can you raise a feature request (issue) on the same? Let me find out a possibility for this plugin. Thanks.

@wing5822 wing5822 changed the title Not an issue - is there a way to change the prop values Feature Request: Change the prop value for a selected component Aug 6, 2020
@abhinaba-ghosh
Copy link
Owner

@wing5822 I appreciate the ticket. Would you be able to provide some more information? Any use cases (sample codes) will help me to dig deep.

@wing5822
Copy link
Author

wing5822 commented Aug 6, 2020

hey @abhinaba-ghosh

I'll use your example

const MyComponent = ({ someBooleanProp }) => (
  <div>My Component {someBooleanProp ? 'show this' : ''} </div>
);

const App = () => (
  <div id="root">
    <MyComponent />
    <MyComponent someBooleanProp={true} />
  </div>
);

ReactDOM.render(<App />, document.getElementById('root'));

We get the react component like so

cy.getReact('MyComponent', { someBooleanProp: 'true' })
  .getProps('someBooleanProp')

But what I want to set the prop value to another value without touching the UI

cy.getReact('MyComponent', { someBooleanProp: 'true' })
  .setProps('someBooleanProp', 'false')

@abhinaba-ghosh
Copy link
Owner

@wing5822 Thanks for the details. You will get an update by upcoming Monday.

@abhinaba-ghosh abhinaba-ghosh added the enhancement New feature or request label Aug 7, 2020
@abhinaba-ghosh
Copy link
Owner

abhinaba-ghosh commented Aug 8, 2020

Hi @wing5822 , after careful analysis, I found out this library can be best suited for E2E testing. Changing prop and state require re-rendering of the React components. So, your tests should have access to source code directly.

Efficient component testing can be achieved using both the libraries:

  • cypress-react-selector
  • cypress-react-unit-test

You can find an existing example of using these two libraries hand-in-hand.

Although I am still validating enhancing this library to handle all possible use cases. You can track here: #23

@abhinaba-ghosh abhinaba-ghosh added discussion and removed enhancement New feature or request labels Aug 8, 2020
@abhinaba-ghosh
Copy link
Owner

Its main idea is to model the entire process of user-application interaction as near to real-life as possible. A user cannot manipulate a component's props and state directly, so the cypress-react-selector is also not supposed to do this. Instead, you can emulate a user action that should lead to intended props/state modification and then check how it affects a page state after re-render.

Also, direct modification of React component props in the real environment in the middle of the React lifecycle can cause unexpected side-effects, make a test unstable and lead to hard-to-locate bugs.

@wing5822
Copy link
Author

That I understand. All good =)

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

No branches or pull requests

2 participants