Using local JSON to fake Firebase for testing?

I am thinking of a testing strategy for an application that uses Firebase for its data warehouse. Although for end-to-end tests it’s enough to make requests for the actual backend, it would be nice to do unit tests of application logic that should not go into Firebase.

I was scouring the website to use something like a local JSON file to mock the Firebase javascript service, but didn't find anything. Does something like this exist? If not, I will write it and publish it on github ...

+8
javascript unit-testing firebase
source share
1 answer

Update

See this meaning and this post for a detailed study of encapsulated TDD versus using layouts for unit testing.

Original publication

It would be very difficult to mock Firebase correctly, as it would mock the most complex data warehouses. Think about it in terms of MySQL ridicule or mocking MongoDB .

Assuming your goal is for the local environment to work offline, a quick solution might be to use a local instance. You can capture firebase-debug.js , save it locally and call set (/ * data * /) to initialize it for standalone operating systems.

Otherwise, encapsulating all Firebase activity into one class or library is the best approach. You can then mock this library, not with Firebase events. And for the quasi- unit test (these are technically not unit tests, since they depend on an external service), the library itself returns to a local stand-alone Firebase instance or sets up the dev database and copies production data (or some seed data).

+7
source share

All Articles