Skip to content

Make services easy to test + docs #1311

@bajtos

Description

@bajtos

This is a follow-up for #1267

When consuming a service using REST connector with template-based configuration: As an app developer, I would definitely want to have few smoke tests to verify that my templates work as intended and match the API provided by the service at the other side. I would like to write an integration test that's using only the service (not the full app!), something along the following lines:

import {GeoService} from '../services/geo.service';
import {expect} from '@loopback/testlab';

describe('GeoService', () => {
  let service: GeoService;
  beforeEach(() => service = new GeoService());

  describe('geocode', () => {
    it('returns geo coords for a given address', () => {
      const result = await service.geocode('107 S B St', 'San Mateo', '94401');
      // { lat: 37.5669986, lng: -122.3237495 }
     expect(result.lat).approximately(37.5669986, 0.5);
     expect(result.lng).approximately(-122.3237495, 0.5);
    });
  });
});

Acceptance criteria

Metadata

Metadata

Assignees

Labels

developer-experienceIssues affecting ease of use and overall experience of LB users

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions