firebase / firebase-functions-test

MIT License
231 stars 48 forks source link

Compilation error with unit test using gen2 onCall function #204

Closed pehagg closed 1 year ago

pehagg commented 1 year ago

Version info

firebase-functions-test: 3.1.0

firebase-functions: 4.4.0

firebase-admin: 11.0.1

Test case

A bit unsure if this is a bug or a feature request :)

Add the following code to the sample test-functions-jest-ts

A gen2 onCall function:

export const myOnCall = onCall<string, string>(({data}) => {
  return `you said: ${data}`;
})

And unit test:

test('myOnCall', async () => {
  const wrapped = wrap(myOnCall);
  await expect(wrapped('foobar')).resolves.toEqual('you said: foobar')
})

Steps to reproduce

See the code snippet above.

Expected behavior

The test code should compile fine and the test should run without any issues.

In addition to this, it would be really nice if there would exist example(s) on how to test onCall functions. Now I had to piece this together by combining different examples and the migration docs.

Actual behavior

I get the following error when using wrap for the function: Argument of type 'CallableFunction<string, string>' is not assignable to parameter of type 'CloudFunction<CloudEvent<unknown>>'. The error message changes slightly if I remove the type annotation, but the end result is the same. Also, the wrap function seems to return a gen1 wrapped function, not a gen2 one, at least if Intellisense it to be trusted, which causes another TS compilation error for the call on the next line: Argument of type 'string' is not assignable to parameter of type 'CallableRequest<string>'.

pehagg commented 1 year ago

Seems to be a duplicate of #163. Closing.