[elm-discuss] Re: Unit testing questions and TDD

2017-03-17 Thread 'Rupert Smith' via Elm Discuss
On Friday, March 17, 2017 at 9:07:24 AM UTC, Richard Wood wrote:
>
> Answering myself. 
> Extensible records - http://elm-lang.org/docs/records#record-types
> Is this a type of polymorphism then?
>

I explored extensible records in this thread:

https://groups.google.com/forum/#!topic/elm-discuss/NVoWA0ZYZNM

Short answer. Yes, it is a type of polymorphism, but be careful you don't 
confuse it with sub-typing because it isn't that kind of polymorphism.

>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Unit testing questions and TDD

2017-03-17 Thread Richard Wood
Answering myself. 
Extensible records - http://elm-lang.org/docs/records#record-types
Is this a type of polymorphism then?

On Friday, 17 March 2017 21:59:08 UTC+13, Richard Wood wrote:
>
> Thanks Max.
>>
>  I see this works. Haven't come across either of these in the docs. Is 
> there a reference or a name for what's happening here that I could search 
> for to learn more?
>  
>
>> Instead of
>>
>> type alias Model = { foo : Foo, bar : Bar }
>>
>> view : Model -> Html Msg
>> view { foo } = -- code that ignores bar
>>
>> -- try
>>
>> view : {a| foo : Foo} -> Html Msg
>> view { foo } = -- same code
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Unit testing questions and TDD

2017-03-17 Thread Richard Wood

>
> Thanks Max.
>
 I see this works. Haven't come across either of these in the docs. Is 
there a reference or a name for what's happening here that I could search 
for to learn more?
 

> Instead of
>
> type alias Model = { foo : Foo, bar : Bar }
>
> view : Model -> Html Msg
> view { foo } = -- code that ignores bar
>
> -- try
>
> view : {a| foo : Foo} -> Html Msg
> view { foo } = -- same code
>
>
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Unit testing questions and TDD

2017-03-16 Thread Max Goldstein
I'm not aware of any really good examples of full webapp tests; maybe it's 
time to write some? That said,

Have you see strategies for effective testing 
? 
It's been updated a bit on master since the last release.

Is there a way to mock or leave out the location in this example or other 
> simplification?


You don't have to use Expect.equal, and you can write your own expectation 
functions using Expect.pass and Expect.fail. But it sounds like App.init 
needs a big record that you don't want to pass, but you want to call 
App.init. So you may need to refactor that function.

In another example, I want to check a view section that I pass the main 
> model to. I obviously don't want to set every property of the model so is 
> there another way?


Instead of

type alias Model = { foo : Foo, bar : Bar }

view : Model -> Html Msg
view { foo } = -- code that ignores bar

-- try

view : {a| foo : Foo} -> Html Msg
view { foo } = -- same code

This syntax means the view function accepts any record as long as it has 
the stated field. It can have extra fields, like Model, or not, like a test 
mock. As a bonus, this will make fuzz shrinking much more effective because 
only relevant fields will need to be shrunk.

Also, in that latter example is there an easy way to see if an html output 
> contains a particular string? 


elm-html-test  


-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[elm-discuss] Re: Unit testing questions and TDD

2017-03-15 Thread Josh Szmajda
Not sure if this helps, but I have a quick elm-18 sample app demonstrating 
the Navigation 
module: https://github.com/joshsz/elm_doc_spike/blob/master/elm/Routing/App.elm

Also curious about TDD in elm, looking forward to replies on that.

On Wednesday, March 15, 2017 at 7:55:27 AM UTC-4, Richard Wood wrote:
>
> In trying unit testing in Elm I found the examples online a bit simplistic 
> or narrow. So I'm wondering if there are some good examples online 
> somewhere of a full variety of unit tests that someone could point me to. 
> Would like to get a feel for when to use them and whether TDD is doable 
> with Elm.
>
> I could also use some specific help here:
> If I use the Navigation module and flags and want to test the initial 
> setup then it seems I need to preset all the fields in the location and the 
> flags object.  
> \()->
> let 
> flags = App.Flags "/path/"
>
> location = { href = ""
> , host = ""
> , hostname = ""
> , protocol = ""
> , origin = ""
> , port_ = ""
> , pathname = ""
> , search = ""
> , hash = ""
> , username = ""
> , password = "" 
> }
>
> model = Tuple.first (App.init flags location)
> in
> Expect.equal model.page App.Home
>
> Is there a way to mock or leave out the location in this example or other 
> simplification?
>
> In another example, I want to check a view section that I pass the main 
> model to. I obviously don't want to set every property of the model so is 
> there another way?
>
> Also, in that latter example is there an easy way to see if an html output 
> contains a particular string? 
>
> Any thoughts appreciated.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.