I'm trying to get started with a unit-tested clojurescript project, based on the figwheel quickstart, but with some tests added. I tried, successfully, to add a basic cljs.test case (test-numbers
from the cljs.test doc) directly into my main file, core.cljs
. When I broke it out into another file for tests only, however, I could not run it from the figwheel repl. Following is the current state of the relevant files, and my repl interaction. What do I need to change so that I can have runnable tests in a separate file from my implementation?
project.clj:
(defproject wheel "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.170"]]
:hooks [leiningen.cljsbuild]
:plugins [[lein-cljsbuild "1.1.2"]
[lein-figwheel "0.5.0-1"]]
:clean-targets ^{:protect false} [:target-path "out" "resources/public/cljs"]
:cljsbuild {
:builds [{:id "dev"
:source-paths ["src/main" "src/test"]
:figwheel true
:compiler {:main "wheel.core"
:asset-path "cljs/out"
:output-to "resources/public/cljs/main.js"
:output-dir "resources/public/cljs/out"}}]})
src/main/core.cljs:
(ns wheel.core
(:require[cljs.test :refer-macros [deftest is testing run-tests]]))
(.log js/console "Hey Seymore")
(deftest test-dev-numbers
(is (= 1 1)))
src/test/test.cljs:
(ns wheel.test
(:require [cljs.test :refer-macros [deftest is testing run-tests]]))
(deftest test-numbers
(is (= 1 1)))
after calls to lein clean
and rlwrap lein figwheel
:
cljs.user=> (in-ns 'wheel.core)
nil
wheel.core=> (run-tests)
Testing wheel.core
Ran 1 tests containing 1 assertions.
0 failures, 0 errors.
nil
wheel.core=> (test-dev-numbers)
nil
wheel.core=> (in-ns 'wheel.test)
nil
wheel.test=> (run-tests)
Testing wheel.test
#object[TypeError TypeError: Cannot read property 'test_numbers' of undefined]
wheel.test=> (test-numbers)
#object[TypeError TypeError: Cannot read property 'test_numbers' of undefined]
wheel.test=>
I was expecting the exact same results from running the tests within the wheel.test namespace as I had from running them in the wheel.core namespace.
Please note also that this is an incremental step - Once I understand how this works, I intend to set up a separate build configuration for test so I can run the tests separately - I'm just trying to take small steps, and I'm stuck on this one.
In my experience each build gives a ns you can
(in-ns 'the-ns)
to and call functions. Trying from other namespaces gives the error you are getting. So for each ns I want to REPL (verb) in, I have a different build id. You might be experiencing the same limitation.(above is simply last comment from discussion).