javascript - React - dynamic properties from strings -
in test suit, trying generate components props dynamically, end components so:
<button primary /> <button secondary />
currently, bit stuck:
[ 'primary', 'secondary' ].foreach((buttontype) => { it(`should render '${buttontype}' button`, () => { const button = mount(<button {...buttontype}>click me</button>); // incorrect - not work // rest of test omitted }); });
any appreciated.
you should replace cardtype
buttontype
in function parameter given foreach.
then, should use following inside test:
const dynamicprops = { [buttontype]: true }; <button {...dynamicprops} />
some elements have been omitted idea. when pass prop without explicit definition, mean someprop={true}
, in above case have use primary
or whatever property of object, value of true.
Comments
Post a Comment