Skip to content

Commit 0dfb0c7

Browse files
test(node-http-handler): add tests for NodeHttpHandler.create() static method
1 parent 71d0e40 commit 0dfb0c7

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/node-http-handler/src/node-http-handler.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,42 @@ describe("NodeHttpHandler", () => {
247247
});
248248
});
249249

250+
describe("create", () => {
251+
const randomRequestTimeout = Math.round(Math.random() * 10000) + 1;
252+
253+
it.each([
254+
["existing handler instance", new NodeHttpHandler()],
255+
["custom HttpHandler object", {
256+
handle: vi.fn(),
257+
} as any],
258+
])("returns the input handler when passed %s", (_, handler) => {
259+
const result = NodeHttpHandler.create(handler);
260+
expect(result).toBe(handler);
261+
});
262+
263+
it.each([
264+
["undefined", undefined],
265+
["an empty options hash", {}],
266+
["empty provider", async () => undefined],
267+
])("creates new handler instance when input is %s", async (_, input) => {
268+
const result = NodeHttpHandler.create(input);
269+
expect(result).toBeInstanceOf(NodeHttpHandler);
270+
});
271+
272+
it.each([
273+
["an options hash", { requestTimeout: randomRequestTimeout }],
274+
["a provider", async () => ({ requestTimeout: randomRequestTimeout })],
275+
])("creates new handler instance with config when input is %s", async (_, input) => {
276+
const result = NodeHttpHandler.create(input);
277+
expect(result).toBeInstanceOf(NodeHttpHandler);
278+
279+
// Verify configuration by calling handle
280+
await result.handle({} as any);
281+
282+
expect(result.httpHandlerConfigs().requestTimeout).toBe(randomRequestTimeout);
283+
});
284+
});
285+
250286
describe("#destroy", () => {
251287
it("should be callable and return nothing", () => {
252288
const nodeHttpHandler = new NodeHttpHandler();

0 commit comments

Comments
 (0)