Skip to content

[Firestore] Using Vitest setSystemTime() throws error #3026

@risalfajar

Description

@risalfajar

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

  • Operating System version: MacOS Sequioa 15.7.2
  • Firebase SDK version: 12.5.0
  • Firebase Product: Firestore
  • Node.js version: 22.19.0
  • NPM version: 10.9.3

[REQUIRED] Step 3: Describe the problem

When using vi.setSystemTime() on integration tests, saving a Date to Firestore throws error.

Steps to reproduce:

  1. Setup Admin NodeJS SDK
  2. Setup Vitest & integration tests
  3. Use vi.setSystemTime()
  4. Save data containing a Date to Firestore
  5. Error
Error: Value for argument "data" is not a valid Firestore document. Input is not a plain JavaScript object (found in field "date").

Relevant Code:

it("date test", async () => {
	vi.setSystemTime(new Date())
	admin.firestore.collection("tests").doc("1").set({ date: new Date() }) // throws error
	vi.useRealTimers()
})

If I were to log the new Date() it will return this:
{"severity":"INFO","message":"MockDate 2025-11-27T14:51:53.132Z"}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions