cljest
is a way to run your ClojureScript files in Jest. It consists of two packages, one in Clojure and one in JavaScript, which allow you to take your ClojureScript tests and run them in Jest.
You'll need two packages, cljest
and jest-preset-cljest
.
Install jest-preset-cljest
using NPM (or Yarn):
npm add --save-dev jest-preset-cljest@1.0.0
And then add cljest
to your deps.edn
or analagous file:
{:deps {com.pitch/cljest {:mvn/version "1.0.0"}}}
For more details, as well as details about getting started and configuration, please see the Installation documentation.
Installation
Writing your first test
Migrating from cljs.test
to cljest
and differences
Unit tests
Component tests
Matchers
Mocking
Async code
General API docs
Running in CI/noninteractive environments
Important information about library versioning
Troubleshooting
Succinctly:
- Great performance. Jest runs tests in parallel using workers, so your test runs scale with your machine, and as you add more tests, in the CI you can shard your tests across multiple machines.
- Full async support. Jest automatically handles promises within tests, including timing them out, and
cljest
has a specialasync
macro to make dealing with async code easier. No more hanging promises in your tests! - Built in support for things like component tests, snapshots, and timer mocks. Jest can be easily configured to use
jsdom
, an environment that lets you mimic a real DOM environment without spinning up a browser, letting you easily test your Reagent, UIx, Helix, or other components, and supports creating snapshots of your components so that changes to the implementation detail of your components doesn't change what the user sees. It also supports mocking timers likesetTimeout
andprocess.nextTick
so that you can have complete control over how time advances in your code, removing the need to mock or abstract timers away yourself. - Huge community. Jest has the largest community and backing of any JavaScript test runner, meaning it has great community created resources such as
testing-library
for good testing practices,jest-axe
for accessibility, and more. Jest is also part of the OpenJS Foundation.
The following items, in no particular order, are on the roadmap as potential additions or improvements to cljest
:
- Incremental test file compilation, which can give even better performance in a large codebase.
- REPL support with JSDOM, so that you can test things on components with the REPL.
Firstly, thanks!
Secondly, please fork the repository and create a PR with your changes. Just keep a couple of things in mind:
- If your change is something that would impact users in a significant way(and therefore potentially requiring a major version bump), please raise an issue so that we can discuss it first.
- Please add tests for your change. In general, if the change is end user facing, write your test in Jest/
cljest
, and otherwise (or if your code is Clojure, not ClojureScript), write your tests in Kaocha.
If something isn't working right, and it's not covered by the troubleshooting documentation, or if something is missing, or if you just generally encounter issues, please create an issue.
MIT