mockfn
mockfn copied to clipboard
Support for mocking `System`
While testing code that relies on environment variables or system properties, it is good to be able to manipulate the System module methods to not pollute the environment with set calls, and in case of env vars, there is no set call.
However while testing the following code, I get an unexpected result:
(testing "mocks System functions"
(macros/providing [(#'System/getenv "A_VARIABLE") "value"]
(is (= "value" (System/getenv "A_VARIABLE")))))
Syntax error compiling var at (mockfn/macros_test.cljc:57:5).
Unable to resolve var: System/getenv in this context
Full report at:
/var/folders/ws/p71fk2m974b3s816dsfcq54c0000gn/T/clojure-16404344592496663391.edn
Tests failed.
This seems to be related to the use of clojure script and clojure mixture.
Note: this is the same behavior with System/getProperty