问题描述
我执行了以下代码(摘自实际用例),并期望获得“ Fake 2 a b”:
(defn real-func
([a] (real-func a "S"))
([a b] (real-func a b "S"))
([a b c] (println "Real " a b c)))
(defn fake-func
([a b] (println "Fake 2" a b)))
(deftest blah-test
(testing "blah blah"
(with-redefs [real-func fake-func] (real-func "a" "b"))))
但是我得到一个错误:
#object[TypeError TypeError: videra_web.effects.graphql_test.real_func.cljs$core$IFn$_invoke$arity$2 is not a function]
奇怪的是,如果我在fake-func
中添加另一个Arity(任何arity),则可以正常工作:例如
(defn fake-func
([a b] (println "Fake 2" a b))
([a b c d e] (println "Fake 5" a b c d e))
)
解决方法
您可能正在运行用:static-fns true
编译的代码,从而阻止了此类操作。
在shadow-cljs
中默认为true,因此,如果您在构建配置中使用该集:compiler-options {:static-fns false}
。