avh4 / avh4/elm-program-test

Port.send a Maybe Value

Open
#81 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
Elm
Stars
95
Forks
28
PR merge metrics
No merged PRs in 30d

Description

I am sending a `Maybe Value` on a port in order to clear the localstorage key when it receives a null value (through sending a Nothing on logout). Trying to do the same in the following code:

```elm
encode : Cred -> Decode.Value
encode (Cred user tokenInfo) =
Encode.object
[ ( "user", User.encode user )
, ( "token", tokenInfoEncoder tokenInfo )
]

storeCredWith : Cred -> Cmd msg
storeCredWith cred =
storeCache (Just (encode cred))

simulateStoreCredWith : Cred -> ProgramTest.SimulatedEffect msg
simulateStoreCredWith cred =
SimulatedEffect.Ports.send "storeCache" (Just (encode cred))

logout : Cmd msg
logout =
storeCache Nothing

port storeCache : Maybe Value -> Cmd msg
```
fails with:
```
TYPE MISMATCH - The 2nd argument to `send` is not what I expect:

SimulatedEffect.Ports.send "storeCache" (Just (encode cred))
#^^^^^^^^^^^^^^^^^#
This `Just` call produces:
#Maybe Value#
But `send` needs the 2nd argument to be:
#Encode.Value#
```

is there a way to simulate this (ie Port.send a Maybe Value) ?

Contributor guide

Open the contributing guide

Research direction

Start with the SimulatedEffect.Ports.send call and the `storeCache : Maybe Value -> Cmd msg` port declaration shown in the issue. Check how simulated port values are typed and whether existing port tests cover nullable values; done means the `Maybe Value` port can be simulated for both `Just` and `Nothing` cases.

Written by the indexing model from the issue text.

Assessment

Domain
testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.