I'm trying to mock the background_downloader package , specifically this line in my class I'm trying to mock:
var status = await fileDownloader.permissions.status(permissionType);
I keep getting error message:
<type 'Future' is not a subtype of type 'Permissions'>
Here is my Test class:
class MockFileDownloader extends Mock implements FileDownloader {}
void main() {
late MockFileDownloader mockFileDownloader;
setUp(() {});
tearDown(() {});
group('BkgrdFileTransferBloc : _initBackgroundFileTransfer() ', () {
setUp(() {
SharedPreferences.setMockInitialValues({BackgroundFileTransfer.notificationDlgShownPref: false});
mockFileDownloader = MockFileDownloader();
var testBasedownloader = FileDownloader().downloaderForTesting;
var permissionService = testBasedownloader.permissionsService;
///these lines here, I'm having issues with
when(() => mockFileDownloader.permissions).thenReturn(permissionService);
when(() => mockFileDownloader.permissions.status(PermissionType.notifications)).thenAnswer((_) async => PermissionStatus.denied);
});
blocTest(
'should show notificationNotGrantedWarning - notificationDlgShownPref = false, ',
build: () {
return BkgrdFileTransferBloc(mockFileDownloader);
},
act: (bloc) => bloc.add(BkgrdFilesTransferEvent.initialize(DownloadTask(url: ''))),
expect:
() => [
TypeMatcher<BkgrdFileTransferState>()
.having((bkgrdFileTransferState) => bkgrdFileTransferState.notificationNotGrantedWarning, 'notificationNotGrantedWarning', isTrue)
.having((bkgrdFileTransferState) => bkgrdFileTransferState.task, 'task', isNotNull),
],
);
});
}