Skip to content

Commit 0ee4189

Browse files
committed
Add API Reference for MockMessaging
1 parent f99c9fb commit 0ee4189

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

API.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Only `MockFirebase` methods are included here. For details on normal Firebase AP
1919
- [Server Timestamps](#server-timestamps)
2020
- [`setClock(fn)`](#firebasesetclockfn---undefined)
2121
- [`restoreClock()`](#firebasesetclockfn---undefined)
22+
- [Messaging](#messaging)
23+
- [`respondNext(methodName, result)`](#respondnextmethodname--result---undefined)
24+
- [`failNext(methodName, err)`](#failnextmethodname--err---undefined)
25+
- [`on(methodName, callback)`](#onmethodname--callback---undefined)
2226

2327
## Core
2428

@@ -242,3 +246,31 @@ Instead of using `Date.now()`, MockFirebase will call the `fn` you provide to ge
242246
##### `Firebase.restoreClock()` -> `undefined`
243247

244248
After calling `Firebase.setClock`, calling `Firebase.restoreClock` will restore the default timestamp behavior.
249+
250+
## Messaging
251+
252+
API reference of `MockMessaging`.
253+
254+
##### `respondNext(methodName, result)` -> `undefined`
255+
256+
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`.
275+
276+
See [docs.js](/test/unit/docs.js) for an example.

0 commit comments

Comments
 (0)