Skip to content

Commit fb18b2a

Browse files
committed
test: make coverage 100%
1 parent 0715083 commit fb18b2a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/http-interface.module.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { GetExchange, HttpInterface } from './decorators';
44
import { StubHttpClient } from './fixtures/stub-http-client';
55
import { HttpInterfaceModule } from './http-interface.module';
66
import { imitation } from './supports';
7+
import { FetchHttpClient } from './supports/fetch-http-client';
8+
import { NodeFetchInjector } from './supports/node-fetch.injector';
9+
import { type HttpClient } from './types';
710

811
describe('HttpInterfaceModule', () => {
912
@HttpInterface('http://localhost:3000')
@@ -14,6 +17,21 @@ describe('HttpInterfaceModule', () => {
1417
}
1518
}
1619

20+
test('should use default http client if not given', async () => {
21+
// given
22+
const module = await Test.createTestingModule({
23+
imports: [HttpInterfaceModule.register()],
24+
}).compile();
25+
await module.init();
26+
const app = module.createNestApplication();
27+
28+
// when
29+
const injector = app.get<{ httpClient: HttpClient }>(NodeFetchInjector);
30+
31+
// then
32+
expect(injector.httpClient).toBeInstanceOf(FetchHttpClient);
33+
});
34+
1735
test('should request with given client', async () => {
1836
// given
1937
const httpClient = new StubHttpClient();

lib/supports/node-fetch.injector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ export class NodeFetchInjector implements OnModuleInit {
2222
const httpProviders = this.getHttpProviders();
2323

2424
httpProviders.forEach((wrapper) => {
25-
const baseUrl: string | undefined = Reflect.getMetadata(
25+
const baseUrl: string = Reflect.getMetadata(
2626
HTTP_INTERFACE_METADATA,
2727
wrapper.metatype.prototype,
2828
);
2929

30-
this.wrapMethods(wrapper, baseUrl ?? '');
30+
this.wrapMethods(wrapper, baseUrl);
3131
});
3232
}
3333

0 commit comments

Comments
 (0)