vendredi 31 janvier 2020

tests inside function calls or for statements in clojure not running

I wrote code that looks something like this

(testing "check that for all these roles there's an alert"
    (binding [*profile* account-exceeded-limits]
      (let [overview-page (overview-container sample-form
                                              :role readonly-no-download)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))
      (let [overview-page (overview-container sample-form
                                              :role dataentry)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))
      (let [overview-page (overview-container sample-form
                                              :role editor)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))
      (let [overview-page (overview-container sample-form
                                              :role member)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))
      (let [overview-page (overview-container sample-form
                                              :role collaborator)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))
      (let [overview-page (overview-container sample-form
                                              :role readonly)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))))

I need to refactor this code to make it drier.

So I tried this

(testing "check that for all these roles theres an alert"
    (for [role [dataentry readonly-no-download editor member collaborator
             readonly]]
      (let [overview-page (overview-container sample-form
                                              :role role)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning")))))

It seemed that tests were not ran.

I also tried this:

(testing "check that for all these roles theres an alert"
(map (fn [role]  (let [overview-page (overview-container sample-form
                                              :role role)]
        (is (dommy/has-class?
             (-> overview-page (sel1 [:div#export-list-panel :.panel-body
                                      :.alert]))
             "alert-warning"))) [dataentry readonly-no-download editor member collaborator
             readonly])))

again, it still seemed that tests were not ran.

What could be causing this? is there a way I can make this test dryer? should I be trying to make tests dryer?

Aucun commentaire:

Enregistrer un commentaire