0

When I use the wrap function from firebase-functions-test I got this error message

Error Message

TypeError: Cannot read properties of undefined (reading 'length')

at isV2CloudFunction (node_modules/firebase-functions-test/lib/main.js:49:26) at wrap (node_modules/firebase-functions-test/lib/main.js:32:9)

Test file code

const firebaseFunctionsTest = require("firebase-functions-test");
const {wrap} =  firebaseFunctionsTest()
describe('Firestore Function Test', ()=>{
    let wrappedFunction = wrap(firestoreFunction.firestoreFunction)

    beforeEach(()=>{    
        wrappedFunction()
    })

})

Function file code

exports.firestoreFunction = functions.firestore.document('/collection/doc').onCreate(
    async(snap, context)=>{
       //function logic
});

function functionA(){
  //function A logic
}

function functionB(){
  //function B logic
}

module.exports = {
  functionA,
  functionB
}
2
  • Have you already checked this documentation? wrap requires you to declare and import the function in your test file code. Also, could you please include your package.json to check what dependencies version are you using. Commented Jul 12, 2022 at 5:09
  • yes, I have declared the function in the test file, the problem is now solved by changing the exports of the function to be with the other functions in the module.exports. Commented Jul 12, 2022 at 5:45

1 Answer 1

1

In the file function, I have used two methods of export, so in the test file when I call firestoreFunction.firestoreFunction it will be undefined.

Changing the function file has solved it.

const firestoreFunction = functions.firestore.document('/collection/doc').onCreate(
    async(snap, context)=>{
       //function logic
});

function functionA(){
  //function A logic
}

function functionB(){
  //function B logic
}

module.exports = {
  firestoreFunction,
  functionA,
  functionB
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.