-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it possible to run unit-test assertions with hspec on a reflex-dom application. #175
Comments
So, to begin, I think the first two And until we have an idea how to do it properly, perhaps it can be worked around for some time like so: widget1 mockButtonClick = do
ev1 <- button "button1" <> mockButtonClick
dy1 <- holdDyn "test6" (const "test7" <$> ev1)
dynText dy1
...
specify "interactive rendering" $ do
(ev0, trigger) <- newTriggerEvent
tw1 <- createTestWidget $ widget1 ev0
testRender tw1 `shouldBe` "<button>button1</button>test6"
testRender tw1 `shouldBe` "<button>button1</button>test6"
trigger ()
testRender tw1 `shouldBe` "<button>button1</button>test7"
testRender tw1 `shouldBe` "<button>button1</button>test7" |
I've got something here that might be interesting. To be useful it would need the ability to kill a I've got something similar for |
@dalaing Glad to see a bit of activity on this ticket, thanks for sharing! I've also been thinking about this on and off since then. I also came to the conclusion that we need a way to construct/destroy widgets under test on the fly. My current thinking is: why not make the API of the testing code such that it accepts any and all |
I've used something like that for Hedgehog and Criterion integration in my older testing repository. It works, but if you can't kill the WebView then your test executable isn't going to exit at the end :/ At the moment my next focus in this area is going to be working on helpers that can be used to query / modify the |
Continuing:
Having had a cursory glance at the code that you've shared, I see that you are using
|
Oh, that sounds like an easy issue, why not use |
Good news everyone, this experimental proof of concept has turned out to work quite well: https://github.com/Wizek/reflex-dom-testing/blob/d1100d8/frontend/src/Main.hs#L155-L178 Can be easily tried out by running
it should print
|
Currently the API is a bit clunky, but with some work I believe it could be cleaned up like: main = runTests 3196 $ do
testWidget widget1
doc~.getElementById "output".innerHTML `shouldBeJS` "0"
doc~.getElementsByTagName "button".js "0".click
doc~.getElementById "output".innerHTML `shouldBeJS` "1" widget1 :: forall t m. MonadWidget t m => m ()
widget1 = do
bClick <- button "Increment"
cnt <- count bClick
elAttr "div" ("id" =: "output") $ do
display cnt
|
@dalaing JSaddle was also causing me grief with exceptions and being able to exit, but I believe, together with @kevroletin we've been able to outwit it like this. |
Next up:
|
This should land pretty soon in reflex-dom. Ref https://github.com/reflex-frp/reflex-dom/blob/e42df1bdc5ea3afd4709f1f847141c792c38df24/reflex-dom-core/test/MountedEvent.hs |
PR is #305 |
Examples:
Maybe we can build an API that is similarly convenient as outlined above, or perhaps even better.
I've created this issue so this can be a space for @ryantrinkle, @dalaing, myself, and any others to collaborate, share ideas, or subscribe to be notified about updates on adding testability to reflex(+dom).
The text was updated successfully, but these errors were encountered: