0.0.19 • Published 7 months ago

@firestore-emulator/jest v0.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@firestore-emulator/jest

This package contains a Jest environment for setup @firestore-emulator/server.

Installation

npm install @firestore-emulator/jest

Usage

configure your jest.config.js:

module.exports = {
  testEnvironment: '@firestore-emulator/jest/environment/node',
  // or "@firestore-emulator/jest/environment/quramy__jest-prisma" if you use prisma. you should install "@quramy/jest-prisma" too.
}

currently, other environments like jsdom are not supported yet. if you need them, please open an issue.

if you use TypeScript you can also load types of your tsconfig.json from this package:

{
  "compilerOptions": {
    "types": ["@firestore-emulator/jest"]
  }
}

then, you can use the emulator global in your tests:

import { initializeApp, App } from 'firebase-admin/app'
import { Firestore, initializeFirestore } from 'firebase-admin/firestore'

let firestore: Firestore
process.env['GCLOUD_PROJECT'] = 'test-project'
beforeAll(() => {
  // for firebase-admin, you need to set the environment variable `FIRESTORE_EMULATOR_HOST`
  process.env['FIRESTORE_EMULATOR_HOST'] = emulator.host
  const app = initializeApp()
  firestore = initializeFirestore(firestoreEmulator)
})

// you can clear the state of the emulator before each test
beforeEach(() => {
  emulator.state.clear()
})

it('something test you want', async () => {
  await firestore.collection('users').doc('alice').create({ name: 'Alice' })

  // you can snapshot test the state of the emulator
  expect(emulator.state.toJSON()).toMatchSnapshot()
})
0.0.19

7 months ago

0.0.18

7 months ago

0.0.17

8 months ago

0.0.16

8 months ago

0.0.15

9 months ago

0.0.14

9 months ago

0.0.13

9 months ago

0.0.12

9 months ago

0.0.11

9 months ago

0.0.10

9 months ago

0.0.9

9 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago