Skip to content

makeDataSnapshot signature not accepting null values #48

@tjokimie

Description

@tjokimie

firebase-functions-test makeDataSnapshot signature is not accepting null values.

This makes it impossible to test code using change.after.exists() without using @ts-ignore, for example:

const foo = functions.database.ref('/foo').onWrite(async (change, context) => {
  if (!change.after.exists()) {
    // skip
    return
  }
  // actual logic
})

In test you would want to use the following code but it throws src/responses/__tests__/index.test.ts:143:54 - error TS2345: Argument of type 'null' is not assignable to parameter of type 'string | number | boolean | object | any[]'.

const afterSnap = test.database.makeDataSnapshot(null, 'foo')
const change = test.makeChange(null, afterSnap)

firebase-functions DataSnapshot constructor still accepts null values as it has any type.

Related signatures:

makeDataSnapshot signature:

val: string | number | boolean | any[] | object,

DataSnapshot constructor in firebase-functions: https://github.com/firebase/firebase-functions/blob/cc663231245256c444e54211911c25fbda0db3d3/src/providers/database.ts#L336

Proposed fix:

The makeDataSnapshot signature should be changed either so that it would also allow null values or unify it with DataSnapshot constructor by allowing any values.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions