Hi guys, I have `MutableSharedFlow` like this ```p...
# flow
k
Hi guys, I have
MutableSharedFlow
like this
Copy code
private val triggerValue = MutableSharedFlow<BloodPressureMeasurement>()
val triggerBpValue: SharedFlow<BloodPressureMeasurement> = triggerValue
I am using in different viewmodel
Copy code
internal fun handleBpValue() {
        viewModelScope.launch(context = <http://Dispatcher.IO|Dispatcher.IO>) {
            someClass.triggerBpValue.collectLatest { measurement ->
               // code in here
            }
        }
    }
I am trying to unit test in
mockk
Copy code
@Test
fun `handleBpValue - `() = runTest {
    coEvery {
        someClass.triggerBpValue
    } returns MutableSharedFlow {
        emit(mockBloodPressureMeasurement)
    }


    subject.handleBpValue()

  
    verify {

    }
}
I am getting error in here
g
You are directly invoking MutableSharedFlow. It has this signature:
Copy code
public fun <T> MutableSharedFlow(
    replay: Int = 0,
    extraBufferCapacity: Int = 0,
    onBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
): MutableSharedFlow<T> {
when you use curly braces you are passing a last argument, which requires type of
onBufferOverflow: BufferOverflow
, so it complains about that type. so try something like
Copy code
val triggerValue = MutableSharedFlow<String>()
    
    @Test
    fun `some test name here`() = runTest {
        every { // I think it does not need coEvery, but not sure
            triggerValue as Flow<String>
        } returns flowOf("123")
    }
k
Ohh nice thanks
Do you have any flow test examples ?
g
nope, it is not an example, but I would recommend this video

https://www.youtube.com/watch?v=hzTU0lh-TIw

k
Thank you so much
I'll take a look
g
🚀