Reputation: 4565
I'm testing my endpoints in offline mode mocking/faking all the data. Based on the Firebase Unit testing of Cloud functions docs, they use it as following:
const req = { query: {text: 'input'} };
const res = {
redirect: (code, url) => {
assert.equal(code, 303);
assert.equal(url, 'new_ref');
done();
}
};
// Invoke addMessage with our fake request and response objects
myFunctions.addMessage(req, res);
My code is similar:
const req = {
}
const res = {
}
updateUser(req, res)
// and this is 'updateUser()' function in another file
export default functions.https.onRequest(async (req, res) => { ... }
So I'm getting the following error:
Argument of type '{}' is not assignable to parameter of type 'Request'. Type '{}' is missing the following properties from type 'Request': get, header, accepts, acceptsCharsets, and 67 more.
How can I avoid putting all the 67 properties? I just want to provide 'method', 'query' or 'body' properties.
Upvotes: 4
Views: 3430
Reputation: 4565
Thanks @mamichels, with their help I've managed to work it out. So I'm posting the solution just in case, it may help someone. I'm using Firebase CF with Express.
import * as express from "express"
...
it("should do something", async () => {
const req = {
method: "POST"
}
const res = {
}
updateUser(req as express.Request, res as express.Response)
})
And my updateUser looks like:
export default functions.https.onRequest(async (req, res) => {
...
})
Upvotes: 5