You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would know if there any way to update the value of props using only one beforeEach and rendering the component only inside him. For example:
Example of code
import{render}from'@testing-library/react-native';describe('Component',()=>{letcomponent;constdefaultProps={prop1: 0,prop2: false,}beforeEach(()=>{component=render(<Component{...defaultProps/>);});it('some test with default props',()=>{});it('some test',()=>{// here, is there any way that I can update the value of `prop1` and `prop2` and test them?});});
I think that I find a way to get updated the props in each test. Using generators. For example:
Example of code using generators
import{render}from'@testing-library/react-native';function*someProps(){constdefaultProps={prop1: 0,prop2: false,}yielddefaultProps;yield{ ...defaultProps,prop2: true};}constcurrentProps=someProps();describe('Component',()=>{letcomponent;letprops;beforeEach(()=>{props=currentProps().next().value;component=render(<Component{...props}/>);});// rest of tests...});});
Does anyone know a better way to have this same result?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would know if there any way to update the value of props using only one
beforeEach
and rendering the component only inside him. For example:Example of code
I think that I find a way to get updated the props in each test. Using
generators
. For example:Example of code using
generators
Does anyone know a better way to have this same result?
Beta Was this translation helpful? Give feedback.
All reactions