5.1.0 • Published 12 days ago

@openapi-typescript-infra/service-tester v5.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

service-tester

main CI

npm version

This module makes it easier for you to write tests for your node.js @openapi-typescript-infra/service microservice. Simply add the module as a dev dependency:

yarn add -D @openapi-typescript-infra/service-tester

Then write a test in /__tests__/startup.test.js:

import request from 'supertest';
import { getReusableApp, clearReusableApp } from '@openapi-typescript-infra/service-tester';
import myService from '../src/index';

describe('my service', () => {
  test('should start', async () => {
    const app = await getReusableApp(myService);
    expect(app).toBeTruthy();
    await request(app).get('/').expect(200);
  });
});

Service call mocking

Nock is so 2010. The future is mock! Since we have typed clients for services these days, mocking them is easier. We've played some nutty tricks with Typescript (well, nutty for me), to enable this kind of syntax:

  mockServiceCall(app.locals.services.myCrazyServ, 'get_some_resource').mockResolvedValue({
    status: 200,
    responseType: 'response',
    body: { resource: true },
    headers: new Headers(),
  });

This will cause calls to app.locals.services.myCrazyServ.get_some_resource() to return {resource: true}. This is just shorthand for jest.spyOn(service, 'method') with knowledge of the traditional return type of OpenAPI service calls.

5.1.0

12 days ago

5.0.0

13 days ago

3.0.2

7 months ago

3.0.1

7 months ago

3.0.0

7 months ago

2.1.1

8 months ago

4.0.1

7 months ago

4.0.0

7 months ago

4.0.3

6 months ago

4.0.2

7 months ago

2.1.0

8 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.6

12 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago