Skip to content

Instantly share code, notes, and snippets.

@TimoKramer
Created February 8, 2018 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimoKramer/14ec4c5b4ab005e12265cb8687bbfe2e to your computer and use it in GitHub Desktop.
Save TimoKramer/14ec4c5b4ab005e12265cb8687bbfe2e to your computer and use it in GitHub Desktop.
testing re-frame
(defn set-active-page-handler
"the handler for the event-function :set-active-page"
[db page slug]
(let [set-page (assoc db :page page)]
(case page
:home {:db set-page}
(:login :register :settings) {:db set-page}
:tours {:db set-page
:dispatch [:get-tours]}
:editor {:db set-page
:dispatch (if slug
[:set-active-tour slug]
[:reset-active-tour])})))
(reg-event-fx
:set-active-page
(fn [{:keys [db]} [_ {:keys [page slug]}]]
(set-active-page-handler db page slug)))
(deftest test-set-active-page-handler
(testing "set-active-page-handler returns correct effects for :home"
(let [db {:page :register}
page :home
slug nil]
(is (= (sut/set-active-page-handler db page slug)
{:db {:page :home}})))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment