I am writing test case for a method that maps one object to another object that has similar properties.
user.ts
mapRequest(){
const common_property =["id","name","age"];
this.req= {};
this.userObj = JSON.parse(window.localStorage.getItem('userObj'));
common_property.forEach(item => req[item] = this.userObj[item]);
this.req.location = "AN";
}
user.spec.ts
it('should mapRequest called ',done => {
component.userObj = { "id": "123" , "name":"xyz" ,"age":25}
component.mapRequest();
expect(component).toBeTruthy();
done();
})
}
though i set the value for userObj Object to get mapped to req obj i am getting error as cannot read property 'id' of null. I am learning to write test case so please correct what is wrong here