Add tests for new "on-changes" middleware

This commit is contained in:
mike-thompson-day8 2015-04-25 09:31:03 +10:00
parent 82b3c87f80
commit c2a9a041eb
1 changed files with 10 additions and 0 deletions

View File

@ -29,3 +29,13 @@
handler) db [nil])]
(is (= (:a new-db)
false)))))
(deftest on-changes
(let [set-a (fn [db v] (assoc db :a v)) ;; handler
mid-ware (middleware/on-changes + [:c] [:a] [:b]) ;; middleware
wrapped (mid-ware set-a)] ;; wrapped middleware
(is (= (wrapped {:a 0 :b 2} 0) ;; no change in 'a'
{:a 0 :b 2}))
(is (= ({:a 4 :b 2} 0) ;; 'a' changed to 0
{:c 2 :a 0 :b 2})))) ;; 'c' is a + b