elm-test
elm-test copied to clipboard
Testing tasks?
Is there any plan to support testing tasks? It looks like there's a couple of alternative testing libraries that support tasks, but surely it would be better to have this in elm-test
? It'd be nice to at least have a note about tasks in the docs.
My use-case is that I have a bunch of JSON decoders for third-party APIs that I'd like to test. These APIs can often return surprising data with mixed types, so it's important to test to make sure all the edge cases are handled.
Sorry if this isn't the proper forum for this question, but I couldn't find any discussion of this elsewhere. Feel free to close this issue if you like. Thanks.
@avh4 has been working on this.
Would it be possible for you to post the code you'd like to test, and what things about it you'd like to test? Motivating use cases are very helpful when designing an API!
I saw that he is rewriting elm-testable
with Native modules, but it looks like the branch he was working on hasn't been touched in a couple months. Do you know if that will be usable with elm-test
, or will it be a standalone testing library like it is today?
My use-case is to test JSON decoders with remote APIs. I wrote this quickly as an example since you asked for code: https://embed.ellie-app.com/xJGBsYQFVGa1/5
So in that example I would want to test that the tradeDecoder
Decoder will actually decode trades from this URL: https://poloniex.com/public?command=returnTradeHistory¤cyPair=USDT_BTC
I have a native binding library, and I want to test it end-to-end (including elm and js integration). Right now, I'm using this helper as a workaround. It's unsafe and straightforward but works:
function unsafeRunSync(task) {
var result;
task.callback(function (innerResult) {
result = innerResult;
});
while (result === undefined);
if (result.ctor === '_Task_succeed')
{
return _elm_lang$core$Result$Ok(result);
}
if (result.ctor === '_Task_fail')
{
return _elm_lang$core$Result$Err(result);
}
throw new Error('unexpected task result');
}
For my use cases, an ideal test API will be something like withTask: (() -> Task err v) -> (Result err v -> Expectation) -> Test
.