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

Adds airbnb/enzyme #1356

Merged
merged 5 commits into from Oct 7, 2017
Merged

Adds airbnb/enzyme #1356

merged 5 commits into from Oct 7, 2017

Conversation

agzam
Copy link
Contributor

@agzam agzam commented Oct 3, 2017

This is my very first attempt to create a cljsjs package (please criticize - so I can learn). I desperately need to make it possible to use Enzyme in browser environment.

I need help with improving this package:

a) it currently only works with React 15
b) I was trying to find a way to use Global exports feature https://clojurescript.org/news/2017-07-30-global-exports ,so it could be required like this:

(require '[cljsjs.enzyme :as enzyme])

but couldn't figure it out

for whatever reason this works:

(require '[cljsjs.enzyme])
js/enzyme

but this still doesn't:

(require '[cljsjs.enzyme :as enz :refer [shallow]])
(prn enz)
(prn shallow)
@Deraen
Copy link
Member

Deraen commented Oct 6, 2017

Please go back to deps-cljs. If you want to use global-exports, update boot-cljsjs to 0.8.1.

@agzam
Copy link
Contributor Author

agzam commented Oct 6, 2017

@Deraen Can you elaborate? You mean I should not be using deps.cljs? Why's that?

@Deraen
Copy link
Member

Deraen commented Oct 6, 2017

deps-cljs task is less lines and one less file, and ensures that file paths etc. are correct.

@agzam
Copy link
Contributor Author

agzam commented Oct 6, 2017

@Deraen
This is ready to be merged.
I hope you've seen my comment in Slack https://clojurians.slack.com/team/U0G75ARHC
I got back where I started (no global-exports). I guess I'm gonna write a wrapper in my app (that would be using this package), something like this:

(ns app.enzyme
  (:require [cljsjs.enzyme]
            [reagent.core :as reagent]
            [reagent.ratom :as ratom]))

(defn- wrapper [enzyme-fn form]
  (let [element (reagent/as-element form)
        node (enzyme-fn element)]
    {:root node
    :node node}))

(defn shallow [form]
  (wrapper js/enzyme.shallow form))

(defn mount [form]
  (wrapper js/enzyme.mount form))

(defn simulate! [event-type {:keys [node root] :as wrapper}]
  (.simulate node event-type)
  (ratom/flush!)
  (reagent/flush)
  (.update root))

@Deraen Deraen merged commit 0670440 into cljsjs:master Oct 7, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants