test. main
Utility functions and types for creating and managing tests within the Cloud Functions for Firebase Test SDK.
Properties
auth
object
Authentication information for the user that triggered the function. This object contains uid
and token
properties for authenticated users. For more detail including token keys, see the
security rules reference.
For an unauthenticated user, this field is null. For event types that do not provide user information (all except Realtime Database) or for Firebase admin users, this field will not exist.
Defaults to null.
authType
(string or undefined)
The level of permissions for a user. Valid values are:
ADMIN
Developer user or user authenticated via a service account.USER
Known user.UNAUTHENTICATED
Unauthenticated actionnull
For event types that do not provide user information (all except Realtime Database).
eventId
(string or undefined)
The event’s unique identifier. If omitted, a random ID will be generated.
params
(non-null Object or undefined)
The values for the wildcards in the reference path that a database or Firestore function is listening to. If omitted, random values are generated.
timestamp
(string or undefined)
Timestamp for the event as an RFC 3339 string. If omitted, the current time is used.
Methods
makeChange
makeChange(before, after) returns Object
Make a Change
object to be used as test data for Firestore and Realtime Database onWrite
and onUpdate
functions.
Parameter |
|
---|---|
before |
Object Snapshot before the write or update. Value must not be null. |
after |
Object Snapshot after the write or update. Value must not be null. |
- Returns
-
non-null Object
AChange
object for testing.
mockConfig
mockConfig(config) returns any type
Mock values returned by functions.config()
.
Parameter |
|
---|---|
config |
Object Key value pairs representing the config to mock. Value must not be null. |
- Returns
-
any type
wrap
wrap(cloudFunction)
Takes a function to be tested, and returns a WrappedFunction
which can be called in test code.
Parameter |
|
---|---|
cloudFunction |
Object A CloudFunction is both an object that exports its trigger definitions at __trigger and can be called as a function using the JavaScript API for Google Cloud Functions. Value must not be null. |
WrappedFunction
WrappedFunction(data, options)
A function that can be called with test data and optional override values for the event context. It will subsequently invoke the function it wraps with the provided test data and a generated event context.
Parameter |
|
---|---|
data |
any type The test data. Value must not be null. |
options |
Object Override values for event context as an
Value may be null. |