Angular service testing: Cannot find name 'asyncData' : <p>So I'm learning how to test services in Angular and I tried to copy the below example in the Angular docs.</p>

<pre><code>let httpClientSpy: { get: jasmine.Spy };
let heroService: HeroService;

beforeEach(() =&gt; {
  // TODO: spy on other methods too
  httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']);
  heroService = new HeroService(&lt;any&gt; httpClientSpy);
});

it('should return expected heroes (HttpClient called once)', () =&gt; {
  const expectedHeroes: Hero[] =
    [{ id: 1, name: 'A' }, { id: 2, name: 'B' }];

  httpClientSpy.get.and.returnValue(asyncData(expectedHeroes));

  heroService.getHeroes().subscribe(
    heroes =&gt; expect(heroes).toEqual(expectedHeroes, 'expected heroes'),
    fail
  );
  expect(httpClientSpy.get.calls.count()).toBe(1, 'one call');
});
</code></pre>

<p>I tried to copy it quite literally, but it gives me the following error:</p>

<blockquote>
  <p>ERROR in src/app/services/find-locals.service.spec.ts(17,38): error
  TS2304: Cannot find name 'asyncData'.</p>
</blockquote>

<p><strong>Can someone help me with replacing this? Or telling me where I might have done something wrong elsewhere?</strong></p>

<p><strong>Here is the test file that copied from the Angular docs:</strong></p>

<pre><code>import {FindLocalsService} from './find-locals.service';

import {HttpClient, HttpClientModule} from '@angular/common/http';

let findLocalsService: FindLocalsService;
let httpClientSpy: { get: jasmine.Spy, post: jasmine.Spy };

beforeEach(() =&gt; {
  httpClientSpy = jasmine.createSpyObj('HttpClient', ['get', 'post']);
  findLocalsService = new FindLocalsService(&lt;any&gt; httpClientSpy, null);
});

it('should save location to server', function () {
  const expectedData: any =
    [{ id: 1, name: 'A' }, { id: 2, name: 'B' }];

  httpClientSpy.post.and.returnValue(asyncData(expectedData));

  findLocalsService.saveLocation('something').subscribe(
    data =&gt; expect(data).toEqual(expectedData),
          fail
  );

  expect(httpClientSpy.post.calls.count()).toBe(1, 'one call');
});
</code></pre>

<p><strong>Here is the service itself</strong></p>

<pre><code>@Injectable()

export class FindLocalsService {

    constructor(private http: HttpClient, private authService: AuthenticationService){}

    saveLocation(locationObj){
        return this.http.post(url + '/findLocals/saveLocation', locationObj);
    }

    getThreeClosestPlayers() {
        const userId = this.authService.currentUser().user._id;
        console.log('entered 3 closest service', userId);

        return this.http.get(url + '/findLocals/getThreeClosestPlayers/' + userId)
            .pipe(
              map((data: any) =&gt; data.obj),
              catchError(this.handleError)
              )
    }
}
</code></pre>
