I am actually studying about enzyme integrated with jest to test stuff on applications. Other things I am using is react and moment.
My question is probably very noob, but I just want to know why there is two argument stuff on this line:
wrapper.find('SingleDatePicker').prop('onFocusChange')({ focused });
is the 'formula' of this, this: objectExample.methodExample('argument1')('argument2');
?
I will provide down below the whole code divided in two: the test code and the code tested.
Code tested:
export default class ExpenseForm extends React.Component {
constructor(props) {
super(props);
this.state = {
calendarFocused: false,
};
}
onFocusChange = ({ focused }) => {
this.setState(() => ({ calendarFocused: focused }));
};
render() {
return (
<div>
{this.state.error && <p>{this.state.error}</p>}
<form onSubmit={this.onSubmit}>
<SingleDatePicker
date={this.state.createdAt}
onDateChange={this.onDateChange}
focused={this.state.calendarFocused}
onFocusChange={this.onFocusChange}
numberOfMonths={1}
isOutsideRange={() => false}
/>
</form>
</div>
)
}
}
test code:
test('should set calendar focus on change', () => {
const focused = false;
const wrapper = shallow(<ExpenseForm />);
wrapper.find('SingleDatePicker').prop('onFocusChange')({ focused });
expect(wrapper.state('calendarFocused')).toBe(focused);
});
So basically, I can understand all the functionality of the code itself and everything.
I just do not understand this second argument ({ focused })
.
I don't even know if this is called 'argument'.
I tweak a bit and took this thing out of the code and it worked the same way.
I am kind of confused if this is vanilla javascript or something of one of these libraries I am using.
...
What I expect: answer for what is this thing and why use it like this. some source of name or something I can browse about it and learn that.