Created
December 24, 2021 14:11
-
-
Save jbrains/ecef3b2a3397740a8496b66f0ad82941 to your computer and use it in GitHub Desktop.
WANTED: A more concise way to execute a side effect in a test without checking its result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
checkSellMultipleItems :: Spec Unit | |
checkSellMultipleItems = | |
describe "Sell Multiple Items" do | |
it "happy path" do | |
(POS.handleCommand $ TextCommand "12345") `shouldSatisfy` (const true) | |
(POS.handleCommand $ TextCommand "total") `shouldEqual` "Total: CAD 27.50" |
It became clear to me after some time that line 5 needs to produce a result that line 6 needs to consume, which eliminates the problem. Perhaps it works better if I interpret `shouldSatisfy` (const true)
as helpful noise.
I'm now slowly making this work. I'm either reinventing or resisting the State monad.
Apparently I wanted discard
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On line 5, I need to execute that action for the effect it will eventually execute, before I execute line 6. I don't want to check the result of line 5, but if I don't check it, the type checker complains. I have temporarily satisfied the type check with the equivalent of "can never fail", but is there a more-concise or more-idiomatic way to have done this?