launchFragment while testing showing error

Using this guide to test dialog https://developer.android.com/guide/fragments/test
The bottom sample

with(launchFragment<MyDialogFragment>()) {
        onFragment { fragment -> // here error
            assertThat(fragment.dialog).isNotNull()
            assertThat(fragment.requireDialog().isShowing).isTrue()
            fragment.dismiss()
            fragment.parentFragmentManager.executePendingTransactions()
            assertThat(fragment.dialog).isNull()
        }
    }

But here it shows error

 onFragment { fragment -> // error below

Type mismatch.
Required:
FragmentScenario.FragmentAction
Found:
(???) → Unit
Cannot infer a type for this parameter. Please specify it explicitly

Source: Android Questions

LEAVE A COMMENT