A Jest testing environment for Firebase functions.
npm i --save-dev jest-environment-firebase-functions
// jest.config.js
/** @type {import('jest').Config} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'jest-environment-firebase-functions',
/** @type {import('jest-environment-firebase-functions').Options} */
testEnvironmentOptions: {
firebaseMode: 'online',
projectId: 'my-project',
storageBucket: 'my-project.appspot.com',
databaseURL: 'https://my-project.firebaseio.com',
keyPath: './serviceAccountKey.json'
}
}
For more on writing tests, see the Firebase documentation.
{
"compilerOptions": {
/* ... */
"typeRoots": [
"./node_modules/@types",
"./node_modules/jest-environment-firebase-functions"
]
/* ... */
}
}
If you'd also like to use the "types"
options, incude "dist"
in the list.
Option | Required | Notes |
---|---|---|
projectId | Yes | |
firebaseMode | No | "online" or "offline" (default) |
keyPath | No | firebaseMode defaults to "online" when set |
storageBucket | No | |
databaseURL | No |