with-redefs 是否需要多个参数?
Does with-redefs requires multiple arities?
我执行了以下代码(摘自真实用例),并期望得到“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 is not a function]
奇怪的是,如果我向 fake-func
添加另一个元数(任何元数),它会起作用:例如
(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
中默认为真,因此如果您在构建配置中使用该集合 :compiler-options {:static-fns false}
。
我执行了以下代码(摘自真实用例),并期望得到“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 is not a function]
奇怪的是,如果我向 fake-func
添加另一个元数(任何元数),它会起作用:例如
(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
中默认为真,因此如果您在构建配置中使用该集合 :compiler-options {:static-fns false}
。