https://github.com/risto-stevcev/cljsjs-sinon
CLJSJS package for Sinon JS
https://github.com/risto-stevcev/cljsjs-sinon
clojurescript sinon
Last synced: 3 months ago
JSON representation
CLJSJS package for Sinon JS
- Host: GitHub
- URL: https://github.com/risto-stevcev/cljsjs-sinon
- Owner: Risto-Stevcev
- Created: 2016-05-14T15:53:30.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-07-18T21:48:33.000Z (almost 9 years ago)
- Last Synced: 2025-01-02T23:46:50.063Z (5 months ago)
- Topics: clojurescript, sinon
- Language: JavaScript
- Homepage: https://clojars.org/cljsjs/sinon
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# cljsjs/sinon
[](https://clojars.org/cljsjs/sinon)
Standalone test spies, stubs and mocks for JavaScript.
After adding the dependency to your project you can require the packaged library like so:
```clojure
(ns application.core
(:require cljsjs.sinon))
```## Examples
```clojure
(ns test-sinon.core
(:require [cljsjs.sinon]
[ajax.core :refer [GET]]))(enable-console-print!)
;; Create a spy
(def myobj (clj->js {"hello" (fn [name] (str "hello, " name "!"))}))
(def spy (js/sinon.spy myobj "hello"))(assert (false? (.-calledOnce spy)))
(println (myobj.hello "mister")) ; hello, mister!
(assert (true? (.-calledOnce spy)))
(assert (true? (.calledWith spy "mister")));; Create a fake server
(def server (js/sinon.fakeServer.create))
(def mock-response [{"id" 12 "comment" "Hey there"}])(.respondWith server "GET" "/some/article/comments.json"
(clj->js [200 {"Content-Type" "application/json"} (-> mock-response clj->js js/JSON.stringify)]))(def callback (js/sinon.spy))
(GET "/some/article/comments.json" {:handler callback})
(.respond server)
(js/sinon.assert.calledWith callback mock-response)
```## Important
It's important to note that Sinon isn't meant to be used in production or fed through minifiers. It's actual use case is either for unit testing or to mock a backend during frontend development. Therefore, it should always be run with `optimizations :none`.