Closed Wizek closed 7 years ago
I don't think it's possible to test code from UI
— besides running it and connecting a browser, of course (There are test frameworks for the latter, I think). One reason is that you can run arbitrary JavaScript code from within UI
, so any mock test would have to be able to interpret arbitrary JavaScript code. I'm afraid that costs much more than a threepenny. :smile:
If the code you want to test does not depend on UI
a lot, then you can try to lift from a lower monad, e.g. IO
or a pure computation, and test the latter instead, e.g.
myCode = liftIO myOtherCode -- --> test myOtherCode instead
Other than that, I'm afraid you're out of luck.
I see, that's sad to hear.
Thanks for the quick response though.
I still have a bit of hope that maybe if I stack unpack threepanny-gui
locally and modify Graphics.UI.Threepenny.Internal to be exported, maybe I can construct a Window that is sufficient for some limited use cases -- e.g. constructing Element
s, maybe those don't require roundtrip connections with a browser.
Closing. Feel free to reopen if more questions remain!
I was thinking that maybe I can run an arbitrary UI action in IO and assert on its results, e.g.
But it seems Window is defined within a hidden module. Would it make sense to expose it perhaps, making it possible to construct transient mock instances? Or is there an alternative, preferred way to test code building on top of UI?