withViewModel

inline fun <VM> withViewModel(crossinline viewModelMatcher: (View, VM) -> Boolean): Matcher<View>

A matcher that performs a check on the ViewModel attached to the checked View's data binding.

This matcher is a workaround and should only be used for matching RecyclerView list items that contain data bindings. Espresso is know to poorly support data binding (hence our need for DataBindingIdlingResourceRule) and this extends to RecyclerView actions: when using actionOnItem the items are matched against a dummy view (because the RecyclerView might not have scrolled to it yet) and the dummy views do not have data bindings applied properly.

This method works by finding the ViewDataBinding bound to the checked View and trying to read its viewModel variable. Views that do not have a data binding or do not have a viewModel variable in its data binding are ignored.