Skip to content

Instantly share code, notes, and snippets.

@jbrains
Created December 24, 2021 14:11
Show Gist options
  • Save jbrains/ecef3b2a3397740a8496b66f0ad82941 to your computer and use it in GitHub Desktop.
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
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"
@jbrains
Copy link
Author

jbrains commented Dec 24, 2021

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?

@jbrains
Copy link
Author

jbrains commented Dec 24, 2021

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.

@jbrains
Copy link
Author

jbrains commented Dec 24, 2021

I'm now slowly making this work. I'm either reinventing or resisting the State monad.

@jbrains
Copy link
Author

jbrains commented Dec 25, 2021

Apparently I wanted discard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment