Question Details

No question body available.

Tags

angular typescript jasmine vitest angular-signals

Answers (1)

April 1, 2026 Score: 1 Rep: 66,965 Quality: Medium Completeness: 80%

We are initializing the service with the signal in the beforeEach which is then configured to the component property, so when modifying the service signal it is not propagated to the component.

Instead, we can use a signal initialized on the test case initialization and use this as the value inside the service.

For the second test case we can use the set method to change the returned mock value, which will solve the issue.

Create a property which will contain the signal:

let mySignalMock: WritableSignal; // { mySignalMock = signal(mockSignalValue); myServiceSpy = createSpyFromClass(TestService); Object.defineProperty(myServiceSpy, 'mySignal', { get: () => mySignalMock, // { expect(component.mySignal().extraProperty).toEqual(undefined); });

For the second test case use set method to modify the returned value.

it('should have the extra property', () => { mySignalMock.set(mockSignalValueWithExtraProperty); // { let component: TestComponent; let fixture: ComponentFixture; let mySignalMock: WritableSignal; //