Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking request? #13

Closed
myguidingstar-zz opened this issue Jun 8, 2014 · 4 comments
Closed

Mocking request? #13

myguidingstar-zz opened this issue Jun 8, 2014 · 4 comments

Comments

@myguidingstar-zz
Copy link
Contributor

AngularJs comes with pretty handy mocking feature in their http api which is really convenient to develop

@r0man
Copy link
Owner

r0man commented Jun 24, 2014

Not sure if I want to go into the mocking business.
Is with-redefs not sufficient for your needs?
How would this mocking thing look like, API wise?

@myguidingstar-zz
Copy link
Contributor Author

omg I fogot that could work on clojurescript. Many thanks

@myguidingstar-zz
Copy link
Contributor Author

Btw, I think an example of with-redefs should be mentioned in README for people like me ;)

@myguidingstar-zz
Copy link
Contributor Author

It turns out that with-redefs doesn't work with async/go macro. I had to make an extra mock namespace and switch between it an cljs-http:

(ns my-ns.mock
  (:refer-clojure :exclude [get])
  (:require-macros [cljs.core.async.macros :refer [alt! go]])
  (:require [cljs.core.async :as async :refer [put! chan <!]]))

(defn get [url]
  (cond
   (= "/some-url" url)
   (let [c (chan)]
     (go (put! c {:body sample-data}))
     c)))

In my main namespace:

(:require ;; [cljs-http.client :as http] ;; => production
               [omtoo.mock :as http] ;; => development
)
;; use http/get etc as usual

Hope this will help somebody else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants