0

I'm trying to write a unit test for a method I have. The method is async and uses an observable to set a property's value. After that method is done I'd like to be sure that property have a length of 10.

The error I get is: Cannot read property 'length' of undefined

Component

  async someMethod() {
    const someObservable = await new Observable(
      (observer: Observer<any>) => {
       ...
      }
    );

    someObservable.subscribe((data) => {
      this.someVariable = data;
    });
  };

Spec

  it('should set someVariable', async () => {
    await component.someMethod();
    expect(component.someVariable.length).toEqual(10);
  });
nandesuka
  • 699
  • 8
  • 22

0 Answers0