title: Mock Injected Service In Unit Testing Nest.js
body: <p>I would like to test my service (Location Service). In this Location Service, I inject repository and other service called GeoLocationService, but got stuck when I am trying to mock this GeoLocationService.</p>
  <p>It throws me an error</p>
  <pre><code>GeolocationService › should be defined
  
      Nest can't resolve dependencies of the GeolocationService (?). Please make sure that the argument HttpService at index [0] is available in the RootTestModule context.
  
  </code></pre>
  <p>Here is the provider's code</p>
  <pre><code>@Injectable()
  export class LocationService {
    constructor(
      @Inject('LOCATION_REPOSITORY')
      private locationRepository: Repository&lt;Location&gt;,
  
      private geolocationService: GeolocationService, // this is actually what I ma trying to mock
    ) {}
  
    async getAllLocations(): Promise&lt;Object&gt; {
  return await this.locationRepository.find()
    }
  ....
  }
  
  </code></pre>
  <p>Here is the test code</p>
  <pre><code>describe('LocationService', () =&gt; {
    let service: LocationService;
    let repo: Repository&lt;Location&gt;;
  
    beforeEach(async () =&gt; {
      const module: TestingModule = await Test.createTestingModule({
        imports: [GeolocationModule],
        providers: [
          LocationService,
          {
            provide: getRepositoryToken(Location),
            useClass: Repository,
          },
        ],
      }).compile();
  
      service = module.get&lt;LocationService&gt;(LocationService);
      repo = module.get&lt;Repository&lt;Location&gt;&gt;(getRepositoryToken(Location));
    });
  
    it('should be defined', () =&gt; {
      expect(service).toBeDefined();
    });
  });
  </code></pre>