This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-29
Channels
- # aws (2)
- # bangalore-clj (2)
- # beginners (36)
- # boot (10)
- # cider (9)
- # cljs-dev (19)
- # clojure (47)
- # clojure-russia (4)
- # clojure-spec (18)
- # clojure-uk (4)
- # clojurescript (71)
- # core-async (20)
- # core-logic (2)
- # css (3)
- # cursive (5)
- # data-science (15)
- # datomic (7)
- # emacs (13)
- # figwheel (4)
- # klipse (1)
- # luminus (5)
- # lumo (1)
- # off-topic (33)
- # re-frame (17)
- # shadow-cljs (1)
- # spacemacs (5)
- # specter (21)
- # unrepl (1)
- # vim (7)
Hello. I can't seem to make stest/instrument's :stub option work. Is that a known limitation by any chance? Can't see any related JIRA tickets.
I've tried a simple test case and also the example given in the spec guide under 'Combining check and instrument'. Seems like the :stub fn is ignored.
This should reproduce what I see (all three invocations return same number but we expect the second number to be a random int)
(defn add2 [a b] 1.1)
(s/fdef add2 :args (s/cat :a int? :b int?) :ret int?)
(println ::a (add2 1 2))
(stest/instrument `add2 {:stub #{`add2}})
(println ::b (add2 1 2))
(stest/unstrument `add2)
(println ::c (add2 1 2))
Code works as expected from clojure repl.
Added a new patch for https://dev.clojure.org/jira/browse/CLJS-2386
If anybody has ideas on how to conditionally require the crypto API on node please comment! I've looked into it a bit and a try require crypto catch approach would work, but could unintentionally include the module when in a build environment targeting the browser and incorporating commonjs or can't that happen?
Also, for the latter case, we maybe could do some additional checks on window being bound and window being bound to the same object in a closure, but that's not ideal either..
@olivergeorge what is :stub
supposed to do. Could probably be made to work, but I’m pretty sure it isn’t currently supported
oh sry, I meant to say I added a new patch again, which could be more efficient than the last one. Now the question is how I can Benchmark the different implementations (maybe on multiple browsers), if needed. Also I could do a proposal on conditional node require if you think it's worth a try. Also no problem, take your time, no one else even has looked into the new patches to catch mistakes, I think.
@dnolen stub should replace the function with a generator (using the :ret spec to generate results).
My use case was isolating a function so side effecting calls were stubbed before running stest/check
There's a section in the Spec Guide covering called "Combining check and instrument" which describes it along with a worked example.
Would you like me to raise a JIRA issue?
Pretty sure the problem is (some #{sym} stub)
not matching inside cljs.spec.test.alpha/instrument-choose-fn. How symbols are managed isn't immediately clear but that's my guess at the cause. The stub arg looks like I expect (e.g. #{cljs.spec.test-test/add2}
) but the sym arg looks like #object[B0]
via nashorn. So no surprise the if statement doesn't do what we expect.
I'll log a ticket and add a patch including a test which fails.
I think the :replace feature has a problem stemming from the same underlying problem. I think resolving stubbing will fix replacing.