Skip to content

QUESTION: How to inject mock of firebase app in unit tests? #1557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
soumak77 opened this issue Apr 10, 2018 · 5 comments
Closed

QUESTION: How to inject mock of firebase app in unit tests? #1557

soumak77 opened this issue Apr 10, 2018 · 5 comments

Comments

@soumak77
Copy link

soumak77 commented Apr 10, 2018

I am using the following library to mock firebase in my unit tests: https://github.com/soumak77/firebase-mock

I am able to create an entire mock of the firebase SDK which I would like angularfire to use during unit testing. In order to achieve this, I would like to pass an instance of a mocked firebase.app.App to angularfire versus angularfire internally creating an app. How would I go about doing this?

@soumak77
Copy link
Author

Anyone have feedback on this? Dependency injection is a must have to test apps that use this library.

@davideast
Copy link
Collaborator

@soumak77 There's nothing out-of-the-box for you to use, but it's possible to set it up yourself. Each AngularFire feature takes in some config tokens that are used to make an app. All you need to do is either alias the @firebase/app module to your firebase-mock module or use Webpack's NormalModuleReplacement plugin. That way it will switch out the real Firebase App module for the mock module and you won't have to do any code changes. Let me know if that sounds like that will work.

@soumak77
Copy link
Author

@davideast angularfire2 already makes use of a FirebaseAppProvider. Is there a way to override this provider to allow me to control how the app is generated?

@davideast
Copy link
Collaborator

@soumak77 No, the FirebaseAppProvider is not used in the services. Due to Zone.js issues we have to create the app inside the service. Therefore your best bet it to replace the module at build time, this is also the easiest option.

@jamesdaniels
Copy link
Member

Closing since we already have an issue to create testing docs, feel free to continue discussing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants