|
2 | 2 |
|
3 | 3 | [](https://pub.dev/packages/firebase_database_mocks) [](https://github.com/sitatec/firebase_database_mocks/actions) [](https://codecov.io/gh/sitatec/firebase_database_mocks) [](https://github.com/google/pedantic) |
4 | 4 |
|
5 | | -Mocks library to write unit tests for FirebaseDatabase (real-time database). Get Instance |
6 | | -`MockFirebaseDatabase.instance`, then pass it around your project as if it was a |
7 | | -`FirebaseDatabase.instance`. This mock keep data in memory while test running. |
| 5 | +A Library that make it easy to write unit tests for FirebaseDatabase (real-time database). |
8 | 6 |
|
9 | 7 | ## Usage |
| 8 | +Get an Instance of `MockFirebaseDatabase` like this : `MockFirebaseDatabase.instance`, then use it in your tests as if it was the reel |
| 9 | +`FirebaseDatabase.instance`. |
| 10 | + |
| 11 | +By default the library keeps the data in memory as long as the tests are running, but you can disable the data persistance as follow: |
| 12 | +`MockFirebaseDatabase.setDataPersistanceEnabled(ennabled: false);`. |
| 13 | + |
| 14 | +If the data persistance is disabled, each time you create an instance of `MockDatabaseReference` either by using the constructor: `MockDatabaseReference()`, or by geting the root reference on `MockFirebaseDatabase` instance : `MockFirebaseDatabase.instance.reference()` a new data store is created instead of using the cached one. |
| 15 | +> ___Note:___ The `MockFirebaseDatabase.setDataPersistanceEnabled()` function is currently experimental, so you might face some issues when you disable the data persitance. |
| 16 | +
|
| 17 | +### Code Sample |
10 | 18 | ```dart |
11 | 19 | import 'package:firebase_database/firebase_database.dart'; |
12 | 20 | import 'package:firebase_database_mocks/firebase_database_mocks.dart'; |
@@ -77,9 +85,9 @@ void main() { |
77 | 85 |
|
78 | 86 | As you can see you don't need to initialize firabase core for testing or call |
79 | 87 | `TestWidgetsFlutterBinding.ensureInitialized()` before using `MockFirebaseDatabase` |
80 | | -but in bonus if you use another firebase service that needs it you can simply call |
| 88 | +but in bonus if you use another firebase service that needs it, you can simply call |
81 | 89 | the `setupFirebaseMocks()` top level function which performs all required operations |
82 | | -for testing a firebase service that isn't fully mocked . |
| 90 | +for testing a firebase service that isn't fully mocked. |
83 | 91 |
|
84 | 92 |
|
85 | 93 | - [Issues](https://github.com/sitatec/firebase_database_mocks/issues) |
|
0 commit comments