From 7a194ce57865062bb9cc1ab77b49fcea1392320b Mon Sep 17 00:00:00 2001 From: Cliff Casey Date: Tue, 16 Jan 2024 14:23:36 -0500 Subject: [PATCH] resolved raw string cljs statement-data bug --- src/xapi_schema/core.cljc | 2 +- test/xapi_schema/core_test.cljc | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/xapi_schema/core.cljc b/src/xapi_schema/core.cljc index 977a284..95add76 100644 --- a/src/xapi_schema/core.cljc +++ b/src/xapi_schema/core.cljc @@ -39,7 +39,7 @@ :else sd)) :cljs (validate-statement-data* (cond - (string? sd) (.parse js/JSON sd) + (string? sd) (js->clj (.parse js/JSON sd)) :else sd)))) #?(:cljs diff --git a/test/xapi_schema/core_test.cljc b/test/xapi_schema/core_test.cljc index 879cbc1..6ece71d 100644 --- a/test/xapi_schema/core_test.cljc +++ b/test/xapi_schema/core_test.cljc @@ -8,6 +8,7 @@ validate-statements validate-statement-data #?(:cljs validate-statement-data-js)]] + [clojure.pprint :refer [pprint]] #?(:clj [clojure.data.json :as json] :cljs [cljs.core :refer [ExceptionInfo]])) #?(:clj (:import [clojure.lang ExceptionInfo]))) @@ -73,7 +74,13 @@ (testing "with string data" (let [statement (json/write-str long-statement)] (testing "it parses and returns the validated data" - (is (= long-statement (validate-statement-data statement))))))) + (is (= long-statement (validate-statement-data statement)))))) + :cljs + (testing "with string data" + (let [json (clj->js long-statement) + json-str (.stringify js/JSON json)] + (testing "it parses and returns the validated data" + (is (= long-statement (validate-statement-data json-str))))))) #?(:cljs (testing "with nested data"