Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

Namespace: test

test

namespace

test is a global namespace that serves as a testing companion to firebase-functions.

Usetest() to initialize the SDK, optionally providing these parameters for online testing:

  • firebaseConfig Firebase config values for initializing a Firebase app for your test code to interact with (e.g. making database writes). It is recommended that you use a project that is specifically for testing. If omitted, mock config values are used and your tests do not interact with a real Firebase app, and all Firebase methods need to be stubbed.
  • pathToServiceAccountKey Path to a service account key file to be used when initializing the Firebase app.

For example:

const test = require('firebase-functions-test')(); // Offline mode

const test = require('firebase-functions-test')(firebaseConfigValues, path/to/key.json'); // Online mode

Interface

Namespaces

Methods

cleanup

static

cleanup()

Complete clean up tasks.

makeChange

static

makeChange(before, after) returns Object

Make aChange object to be used as test data for Firestore and Realtime DatabaseonWrite andonUpdate 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

static

mockConfig(config)

Mock values returned byfunctions.config().

Parameter

config

Object

Key value pairs representing the config to mock.

Value must not be null.

wrap

static

wrap(cloudFunction) returns test.WrappedFunction

Takes a function to be tested, and returns aWrappedFunction 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.

Returns

non-nulltest.WrappedFunction 

WrappedFunction

static

WrappedFunction(data, options)

A function type 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 anEventContextOptions object.

Value may be null.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2019-12-03 UTC.


[8]ページ先頭

©2009-2025 Movatter.jp