I'm trying to test a component which uses a Service with a property called inside a method's component. I need to mock and change that property depending on the test.
I have this:
export class XService{
xProperty:boolean;
}
export class XComponent{
ctor(private xService:XService){
}
xMethod():void{
if(xService.xProperty){
//some code
}
}
}
I tried it creating a mock and adding the property in beforeEach method
beforeEach(() => {
/**more code**/
xServiceMock = jasmine.createSpyObj(['xMethodService']);
xServiceMock ['xProperty'] = false;
});
That works well until I have to change the value in one of the tests. When I do it, the value is not refreshed.
it('x validation', () => {
xServiceMock.xProperty = true;
fixture.detectChanges();
component.xMethod();<<<-- When it calls the method the change to TRUE is not refreshed
expect(/****/).toBe(false);
});
Do you know if I can mock that property with Jasmine? Is it possible?