I have a function defined as:
(defn strict-get
[m key]
{:pre [(is (contains? m key))]}
(get m key))
And then I have a test for it:
(is (thrown? java.lang.AssertionError (strict-get {} :abc)))
However this test fails:
;; FAIL in () (myfile.clj:189)
;; throws exception when key is not present
;; expected: (contains? m key)
;; actual: (not (contains? {} :abc))
What is needed to check that the assertion would throw an error?
The reason your assertion fails because you are nesting two
is. The innerisalready catches the exception so the outeristest then fails because nothing is thrown.