Run Tests using Shadow CLJS

I want to run a simple ClojureScript test, but am getting an error:

$ npx shadow-cljs compile test
shadow-cljs - config: /Users/blah/cljslab/shadow-cljs.edn
[:test] Compiling ...
The required namespace "cljslab.core.actions.building-blocks" is not available, it was required by "cljslab/core/actions/building_blocks_test.cljs".



  "name": "cljslab",
  "version": "0.0.1",
  "private": true,
  "devDependencies": {
    "shadow-cljs": "2.22.9"


;; shadow-cljs configuration


  {:target :node-script
   :output-to "out/cljslab/cljslab.js"}

  {:target :node-test
   :output-to "out/test/cljslab/cljslab-test.js"
   :autorun true}}}


(ns cljslab.core.actions.building-blocks)

(defn action [x] x)


(ns cljslab.core.actions.building-blocks-test
  (:require [cljs.test :refer (deftest is testing)]
            [cljslab.core.actions.building-blocks :refer (action)]))

((deftest name-test
   (testing "Context of the test assertions"
     (is (= 2 (action 1))))))

What is missing?

You have added src/cljslab to :source-paths instead of src. It means that cljslab is not a part of namespaces anymore.

Instead, you should structure your project so that src and test are side by side and both are included in :source-paths.

1 Like

Thank you! This change (and changing the directory structure as you suggested) solved the problem:

  • I do not see a button for “mark as answer” - or similar.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.