Skip to content

Commit

Permalink
Merge pull request #973 from Leffe108/fix/testing-docs
Browse files Browse the repository at this point in the history
doc: sync testing docs with code
  • Loading branch information
bartekpacia authored Oct 13, 2024
2 parents eaaf136 + 7710bc1 commit c51ec65
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/testing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ description: Test your app with Location

# Testing

If you want to set a custom LocationPlatform for testing you can use the `setLocationInstance` property.
If you want to set a custom Location for testing you can use the `Location.instance` property.
Here is an example with Mocktail

```dart
import 'package:flutter_test/flutter_test.dart';
import 'package:location/location.dart';
import 'package:mocktail/mocktail.dart';
class MockLocationPlatform extends Mock implements LocationPlatform {}
class MockLocation extends Mock implements Location {}
void main() {
testWidgets('get location ...', (tester) async {
final mock = MockLocationPlatform();
final mock = MockLocation();
when(mock.getLocation).thenAnswer(
(invocation) async => LocationData(latitude: 42, longitude: 2),
(invocation) async => LocationData.fromMap({'latitude': 42, 'longitude': 2}),
);
setLocationInstance(mock);
Location.instance = mock;
});
}
```

0 comments on commit c51ec65

Please sign in to comment.