expect-more | Curried Type Testing library , and Test Matchers for Jest | Testing library
kandi X-RAY | expect-more Summary
kandi X-RAY | expect-more Summary
Curried Type Testing library, and Test Matchers for Jest
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of expect-more
expect-more Key Features
expect-more Examples and Code Snippets
Community Discussions
Trending Discussions on expect-more
QUESTION
I have a function to handle connecting to Cloud Firestore through the Admin SDK. I know the function works fine, as the app connects and allows writing to the database.
Now I am trying to test this function with Jest. To avoid testing outside the scope of this function, I am mocking the firebase-admin Node module. However, my test is failing with the error "TypeError: admin.firestore is not a function".
My function and tests are both written in TypeScript, run via ts-jest, but I don't think this is a TypeScript error, as VS Code has no complaints. I believe this is an issue with Jest's automatic mocking.
admin.firebase()
is a valid call. The TypeScript definition file defines it as function firestore(app?: admin.app.App): admin.firestore.Firestore;
I've read over the Jest docs, but I'm not understanding how to fix this.
This is my function:
...ANSWER
Answered 2020-May-12 at 06:55Your code looks good. jest.mock
mocks all the methods of the library and, by default, all of them will return undefined
when called.
The problem you are seeing is related to how the firebase-admin
module methods are being defined.
In the source code for firebase-admin
package, the initializeApp
method is being defined as a method in the FirebaseNamespace.prototype
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install expect-more
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page