Skip to content

Commit 7c1521b

Browse files
committed
Update readme
1 parent fa5f550 commit 7c1521b

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22

33
[![Pub Version](https://img.shields.io/pub/v/firebase_database_mocks)](https://pub.dev/packages/firebase_database_mocks) [![test: passing](https://github.com/sitatec/firebase_database_mocks/actions/workflows/main.yml/badge.svg)](https://github.com/sitatec/firebase_database_mocks/actions) [![codecov](https://codecov.io/gh/sitatec/firebase_database_mocks/branch/main/graph/badge.svg?token=YLBE21OXGR)](https://codecov.io/gh/sitatec/firebase_database_mocks) [![style: effective dart](https://img.shields.io/badge/style-pedantic-blue)](https://github.com/google/pedantic)
44

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).
86

97
## 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
1018
```dart
1119
import 'package:firebase_database/firebase_database.dart';
1220
import 'package:firebase_database_mocks/firebase_database_mocks.dart';
@@ -77,9 +85,9 @@ void main() {
7785

7886
As you can see you don't need to initialize firabase core for testing or call
7987
`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
8189
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.
8391

8492

8593
- [Issues](https://github.com/sitatec/firebase_database_mocks/issues)

0 commit comments

Comments
 (0)