Closed sentry-io[bot] closed 11 months ago
The issue has been successfully addressed by the pull request #935. In order to further validate and ensure the effectiveness of the fix, I've created the unit test below:
// Import necessary packages for testing
import 'dart:async';
import 'package:flutter_test/flutter_test.dart';
import 'package:mawaqit/src/helpers/Api.dart';
// Define necessary classes for testing
class Weather {}
class Mosque {
final String uuid;
Mosque({required this.uuid});
}
class WeatherService {
Weather? weather;
late StreamSubscription<void> _weatherSubscription =
Stream.empty().listen((_) {});
late Future<dynamic> Function(String) _getWeather;
WeatherService({Future<Weather> Function(String)? getWeather})
: _getWeather = getWeather ?? Api.getWeather;
void loadWeather(Mosque mosque) {
if (mosque.uuid != null) {
_weatherSubscription.cancel().catchError((e) {});
}
}
}
void main() {
group('Weather functionality tests', () {
late WeatherService weatherService;
setUp(() {
weatherService = WeatherService();
});
// Test case: Verify that 'loadWeather' cancels subscription and sets weather to null when an exception occurs
test('loadWeather cancels subscription', () async {
weatherService._getWeather =
(String uuid) => throw Exception('Test exception');
weatherService.loadWeather(Mosque(uuid: 'test_uuid'));
expect(weatherService.weather, isNull);
});
});
📷 Before the fix :
📷 After the fix :
@ghassenbenzahra123 which PR is linked to this issue ? can you link it please
Sentry Issue: ANDROIDTV-3Q