how to set value to readonly property in typescript 1

how to set value to readonly property in typescript

beforeEach(() => {
    TestBed.configureTestingModule({
      providers: [
        MyService
      ]
    });
    service = TestBed.get(MyService);
    const timeIntervals = 'timeIntervals';
    Object.defineProperty(service, timeIntervals, { value: timeLists });
  });

Here is what the above code is Doing:
1. We are creating a mock service using the TestBed.configureTestingModule() method.
2. We are getting the instance of the service using the TestBed.get() method.
3. We are creating a property on the service instance using the Object.defineProperty() method.

Now, let’s see how to use the mock service in our test:

Similar Posts