cljs.test :after fixture not called if test errors

48 views
Skip to first unread message

Stuart Campbell

unread,
Nov 24, 2020, 6:17:03 PM11/24/20
to Clojure
Hello,

I'm experimenting with fixtures and it seems like :after fixtures aren't run if a test unexpectedly errors. E.g.:

(use-fixtures :once {:before #(println "before")
                     :after #(println "after")})

(deftest a-test
  (raise (js/Error. "oops")))

In this example I expected to see "after" printed somewhere after the test failed. Is this intentional?

(I'm writing some tests for an Electron app using Spectron and want to make sure the app is always shut down after the tests are complete.)

Regards,
Stuart

Estevo U. C. Castro

unread,
Nov 25, 2020, 12:23:22 AM11/25/20
to Clojure
Try

(use-fixtures :once
  (fn [f]
    (println "before")
    (try (f)
      (finally (println "after")))))

Stuart Campbell

unread,
Nov 25, 2020, 1:19:46 AM11/25/20
to Clojure
That unfortunately doesn't work for async tests, which require the map fixture style (with :before/:after keys).

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/N28pFLtNWpo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/84dff1cf-6ea0-438c-a4c0-fac097223201n%40googlegroups.com.

David Nolen

unread,
Nov 25, 2020, 9:46:13 PM11/25/20
to clojure
In the async case just handle the error yourself and fail the test. There's really not a good way to detect async errors since there isn't one way to. do async (promises, core.async, etc.).

David

You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAFuJp1n1Vz8NKf%3DmxakTYn1EXF8UUqTQwc5NiDUKGMOj-BKBsQ%40mail.gmail.com.

Stuart Campbell

unread,
Nov 27, 2020, 10:31:37 PM11/27/20
to Clojure
Reply all
Reply to author
Forward
0 new messages