You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -117,7 +122,7 @@ function onValue (_snapshot_) {
117
122
}
118
123
ref.on('value', onValue);
119
124
ref.set({
120
-
foo:'bar';
125
+
foo:'bar',
121
126
});
122
127
ref.flush();
123
128
console.assert(ref.getData().foo==='bar', 'data has foo');
@@ -169,26 +174,46 @@ ref.flush(); // added foo after null
169
174
170
175
Authentication methods for simulating changes to the auth state of a Firebase reference.
171
176
172
-
##### `changeAuthState(authData)` -> `undefined`
177
+
##### `changeAuthState(user)` -> `undefined`
173
178
174
-
Changes the active authentication credentials to the `authData` object. Before changing the authentication state, `changeAuthState` checks whether the `authData` object is deeply equal to the current authentication data. `onAuth` listeners will only be triggered if the data is not deeply equal. To simulate no user being authenticated, pass `null` for `authData`. This operation is queued until the next `flush`.
179
+
Changes the active authentication credentials to the `authData` object.
180
+
Before changing the authentication state, `changeAuthState` checks the
181
+
`user` object against the current authentication data.
182
+
`onAuthStateChanged` listeners will only be triggered if the data is not
183
+
deeply equal.
175
184
176
-
`authData` should adhere to the [documented schema](https://www.firebase.com/docs/web/api/firebase/onauth.html).
185
+
`user` should be a `MockUser` object or an object with the same fields
186
+
as `MockUser`. To simulate no user being authenticated, pass `null` for
187
+
`user`. This operation is queued until the next `flush`.
177
188
178
189
Example:
179
190
180
191
```js
181
-
ref.changeAuthState({
192
+
ref.changeAuthState(newMockUser(ref, {
182
193
uid:'theUid',
183
-
provider:'github',
184
-
token:'theToken',
185
-
expires:Math.floor(newDate() /1000) +24*60*60, // expire in 24 hours
metadata: {}, // firebase-mock offers limited support for this field
204
+
customClaims: {
205
+
isAdmin:true,
206
+
// etc.
207
+
},
208
+
_idtoken:'theToken',
209
+
_tokenValidity: {
210
+
authTime:'2019-11-22T08:46:15Z',
211
+
issuedAtTime:'2019-11-22T08:46:15Z',
212
+
expirationTime:'2019-11-22T09:46:15Z',
213
+
},
214
+
}));
190
215
ref.flush();
191
-
console.assert(ref.getAuth().auth.myAuthProperty, 'authData has custom property');
216
+
console.assert(ref.getAuth().displayName==='Mr. Meeseeks', 'Auth name is correct');
192
217
```
193
218
194
219
<hr>
@@ -201,6 +226,13 @@ Finds a user previously created with [`createUser`](https://www.firebase.com/doc
201
226
202
227
Finds a user previously created with [`createUser`](https://www.firebase.com/docs/web/api/firebase/createuser.html). If no user was created with the specified `email`, the promise is rejected.
203
228
229
+
##### `updateUser(user)` -> `Promise<MockUser>`
230
+
231
+
Replace the existing user with a new one, by matching uid. Throws an
232
+
error if no user exists whose uid matches the given user's uid. Resolves
233
+
with the updated user when complete. This operation is queued until the
234
+
next flush.
235
+
204
236
## Server Timestamps
205
237
206
238
MockFirebase allow you to simulate the behavior of [server timestamps](https://www.firebase.com/docs/web/api/servervalue/timestamp.html) when using a real Firebase instance. Unless you use `Firebase.setClock`, `Firebase.ServerValue.TIMESTAMP` will be transformed to the current date (`Date.now()`) when your data change is flushed.
@@ -214,3 +246,31 @@ Instead of using `Date.now()`, MockFirebase will call the `fn` you provide to ge
214
246
##### `Firebase.restoreClock()` -> `undefined`
215
247
216
248
After calling `Firebase.setClock`, calling `Firebase.restoreClock` will restore the default timestamp behavior.
When `methodName` is next invoked, the `Promise` (that is returned from the `methodName`) will be resolved with the specified `result`. This is useful for testing specific results of firebase messaging (e. g. partial success of sending messaging). The result will be triggered with the next `flush`.
257
+
258
+
If no result is specified, `methodName` will resolve a default response.
259
+
260
+
`result` must not be undefined.
261
+
262
+
<hr>
263
+
264
+
##### `failNext(methodName, err)` -> `undefined`
265
+
266
+
When `methodName` is next invoked, the `Promise` will be rejected with the specified `err`. This is useful for simulating validation or any other errors. The error will be triggered with the next `flush`.
267
+
268
+
`err` must be a proper `Error` object and not a string or any other primitive.
269
+
270
+
<hr>
271
+
272
+
##### `on(methodName, callback)` -> `undefined`
273
+
274
+
When `methodName` is next invoked, the `callback` will be triggered. The callback gets an array as argument. The array contains all arguments, that were passed on invoking `methodName`. This is useful to assert the input arguments of `methodName`.
0 commit comments