Angular service method that returns data from a database returns undefined in the testing spec

I have a method in myservice.ts called getEvents() that creates an array, call http.get method and fills the array, to return it with database information. However, when I call this method in my myservice.spec.ts file, it returns undefined.

myservice.service.ts:

```
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { MyComponent } from './mycomponent.component.ts';

@Injectable({
  providedIn: 'root'
})
export class MyService {
    getEvents(): string[] {
        const events = [];
        this.http.get<MyClass[]>('http://localhost:3001/getEvents')
                 .subscribe(subscribedEvents => {
                    for (const event of subscribedEvents ) {
                        events.push(event);
                    }
                 });
        return events;
    }
  constructor(private http: HttpClient) { }
}

```

myservice.service.spec.ts:

```
import { async, TestBed } from '@angular/core/testing';
import { HttpClientModule } from '@angular/common/http';
import { MyService } from './myservice.service';

describe('MyService', () => {
    beforeEach(async(() => {
        TestBed.configureTestingModule({
          imports: [ HttpClientModule ],
          providers: [ MyService ]
        })
        .compileComponents();
      }));
  it('getEvents', () => {
    const service: MyService = TestBed.get(MyService);
    expect(service.getEvents()[0]).toEqual('FirstEvent');
  });
});

```

getEvents() makes a call to my backend server (verified by the component and by Postman), takes the data from .subscribe(), and places that into an array. The filled array gets returned.
This works fine in my component, but in the service spec, it returns undefined.

I apologize for the generic names; I do not want my original code posted.

Error:

```
Expected undefined to equal 'FirstEvent'.

```