infinite_scroll_pagination
infinite_scroll_pagination copied to clipboard
Unable to mock PagingController with latest mockito and infinite_scroll_pagination
Tools:
- flutter 2.8.1
- mockito ^5.0.17
- infinite_scroll_pagination ^3.1.0
Using mockito's GenerateMocks annotation, @GenerateMocks([PagingController]), results in the following error and build_runner failure:
Invalid @GenerateMocks annotation: Mockito cannot generate a valid mock class which implements 'PagingController' for the following reasons:
The property accessor 'PagingController.firstPageKey' features a non-nullable unknown return type, and cannot be stubbed without a dummy generator specified on the MockSpec.
Any thoughts on a potential solution for this?
Workaround solution:
abstract class FirstPageKey {
T firstPageKey<T>(T a, int b);
}
T firstPageKeyShim<T>(T a, int? b) {
if (a is int) return a;
throw 'unknown';
}
@GenerateMocks(
[],
customMocks: [
MockSpec<PagingController>(
returnNullOnMissingStub: true,
fallbackGenerators: {#firstPageKey: firstPageKeyShim}),
],
)