I have encountered strange behavior in the output of my ES6 program in WebStorm. I am using Babel to transpile the code. Can someone help me understand what's going on?
class DateLocationValidator{
_appointments;
constructor(appointments){
this._appointments = appointments;
console.log(this._appointments);
}
validate(appointmentViewModel)
{
console.log('validating');
if(this._appointments==null || this._appointments.length==0) {
console.log('appointments null');
console.log(this._appointments);
return {
outcome:true,
reason:'',
conflictId:0
};
}else{
console.log('appointments not null');
var result = this._appointments.where(function(appointment)
{
console.log('searching');
if(appointment.startDate==appointmentViewModel.startDate && appointment.startDate==appointmentViewModel.startDate){
console.log('found');
return true;
}
});
if(result.length>0){
return {
outcome:true,
reason:'There is already an appointment scheduled for this location on this date',
conflictId:result[0].id
};
}
}
}
}
Below is a test scenario:
it("Fails when appointment clashes exactly",function(){
try {
let appointments = [new AppointmentViewModel(1, new Date(2015, 1, 1), new Date(2015, 1, 2))];
let validator = new DateLocationValidator(appointments);
let appointmentViewmodel = new AppointmentViewModel(1, new Date(2015, 1, 1), new Date(2015, 1, 2));
let result = new validator.validate(appointmentViewmodel);
expect(result.outcome).toBe(false);
}
catch(excep){
console.log(excep)
expect(true).toBe(false);
}
});
'appointments null' message gets printed even after the array has been correctly initialized in the constructor.
Additionally, attempting to call a function from validate results in an undefined error. Can anyone provide assistance?
Thanks, M