Closed ricardojmendez closed 8 years ago
Is it okay to add it as a <script src="path/to/jquery">
?
As discussed on the chat: yes, adding a script link directly on the test html is file.
+1
As an interim measure - how about just including cljsjs/jquery
as a test dependency (and requiring it in your runner)
@crisptrutski +1 for CLJSJS :D
Hi @ricardojmendez,
After trying it a couple of alternatives in the REPL (tweaks on clojurescript.test
command line builder) I realize that @crisptrutski is right. The ClojureScript compiler already has a method to inject dependencies! If your production build expects $
and you server it through a CDN, then you can always add the snippet in :foreign-libs
for the test build.
To explore that solution I've put together this repo which shows how to set it up and run it. These are the important parts:
:cljsbuild {
:builds [{:id "test"
:source-paths ["src"]
:compiler {:main doo-with-deps.core
:output-to "out/testable.js"
:source-map-timestamp true
:foreign-libs [{:file "resources/vendor/jquery.js"
:provides ["jquery.core"]}]}}]}
and in your test file:
(ns doo-with-deps.core
(:require [cljs.test :refer-macros [deftest is testing]]
[jquery.core]))
(deftest external-deps
(testing "When starting the application, jQuery is present"
(is (exists? js/$))))
Does this solve your problem?
@bensu: Let me give it a shot and get back to you later this week - I'm currently tied up on something where doo isn't an option (testing inside a Chrome extension).
Yes, the dependencies solve exactly this issue.
When running tests on doo, it'd be ideal to have a way to inject some Javascript libraries. For instance, Jayq expects you to have linked to the jQuery library from your page, so we'd need to inject it into the tests.
I'm using phantom, but expect this is something desirable for others as well.