Skip to content

Commit

Permalink
Add example for Manual Worker to README
Browse files Browse the repository at this point in the history
  • Loading branch information
brandoncorrea committed May 17, 2024
1 parent f5ee623 commit b5f9863
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,47 @@ Add the following dependency to your deps.edn file:
(set! js/sessionStorage (mem-store/->MemStorage))
)
```

### Manual Worker

#### In Your Tests

```clojure
(ns acme.mimic-spec
(:require [acme.mimic :as sut]
[bwa.mimic.spec-helper :as spec-helper]
[speclj.core :refer-macros [describe it should=]]))

(describe "Mimic"
(spec-helper/with-manual-worker)

(it "travels through time"
(sut/start-clock)
(sut/time-travel)
(let [[timeout] (worker/timeouts)
[interval] (worker/intervals)]
(should= 1000 (:delay interval))
(should= 88 (:delay timeout))
(should= 0 @sut/seconds)
(worker/tick! interval)
(should= 1 @sut/seconds)
(worker/tick! interval)
(should= 2 @sut/seconds)
(worker/tick! timeout)
(should= 122 @sut/seconds)
(worker/tick! interval)
(should= 123 @sut/seconds)))
)
```

```clojure
(ns acme.mimic)

(def seconds (atom 0))

(defn start-clock []
(js/setInterval #(swap! seconds inc) 1000))

(defn time-travel []
(js/setTimeout #(swap! seconds + 120) 88))
```

0 comments on commit b5f9863

Please sign in to comment.