javascript - Jest Enzyme Simulate Value -


i set wrapper follows:

const wrapper = shallow(<uploads       availabletemplates={[]}       filters={{ commodity: '' }}       actions={{         setfilter: (e) => { wrapper.setprops({ filters: e }); }       }}     />); 

the goal of following test change radio value of 'checked' default false true:

const input = wrapper.find('input').at(0);      input.simulate('change', { target: input.props() });     expect(wrapper.find('input').at(0).node.props.checked).toequal(true); 

without further ado, here question: when create test below check default value of radio (which should false), i'm getting true back. presumably because have altered true early. there way reset input default state each subsequent test?

expect(wrapper.find('input').at(0).node.props.checked).toequal(false); 

of course, move test above other 1 curious why above happening.

reason above seems testing same instance of wrapper each time. when changed value true persist through rest of tests. counteract this, created getwrapper function call fresh instance of wrapper each time:

const getwrapper = () => {   const wrapper = shallow(<uploads     availabletemplates={[]}     filters={{ commodity: '' }}     actions={{       setfilter: (e) => { wrapper.setprops({ filters: e }); }     }}   />);   return wrapper; }; 

in test:

const wrapper = getwrapper(); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -