diff --git a/src/targets/clojure/clj_http/client.test.ts b/src/targets/clojure/clj_http/client.test.ts new file mode 100644 index 000000000..edb876683 --- /dev/null +++ b/src/targets/clojure/clj_http/client.test.ts @@ -0,0 +1,34 @@ +import type { Request } from '../../..'; + +import { runCustomFixtures } from '../../../fixtures/runCustomFixtures'; + +runCustomFixtures({ + targetId: 'clojure', + clientId: 'clj_http', + tests: [ + { + it: 'should not crash if there is no `postData.text`', + input: { + headers: [ + { + name: 'accept', + value: 'application/json', + }, + { + name: 'content-type', + value: 'application/json', + }, + ], + postData: { + mimeType: 'application/json', + }, + bodySize: 0, + method: 'POST', + url: 'https://httpbin.org/anything', + httpVersion: 'HTTP/1.1', + } as Request, + options: {}, + expected: 'should-not-crash.clj', + }, + ], +}); diff --git a/src/targets/clojure/clj_http/client.ts b/src/targets/clojure/clj_http/client.ts index 43f6449c6..06c20b7bc 100644 --- a/src/targets/clojure/clj_http/client.ts +++ b/src/targets/clojure/clj_http/client.ts @@ -45,7 +45,9 @@ const jsType = (input?: any) => { }; const objEmpty = (input?: any) => { - if (jsType(input) === 'object') { + if (input === undefined) { + return true; + } else if (jsType(input) === 'object') { return Object.keys(input).length === 0; } return false; diff --git a/src/targets/clojure/clj_http/fixtures/should-not-crash.clj b/src/targets/clojure/clj_http/fixtures/should-not-crash.clj new file mode 100644 index 000000000..382de39e1 --- /dev/null +++ b/src/targets/clojure/clj_http/fixtures/should-not-crash.clj @@ -0,0 +1,4 @@ +(require '[clj-http.client :as client]) + +(client/post "https://httpbin.org/anything" {:content-type :json + :accept :json}) \ No newline at end of file