katowulf / mockfirebase

Firebase mock library for writing unit tests (experimental)
157 stars 40 forks source link

Trouble creating two references to same data #93

Closed TmanTman closed 9 years ago

TmanTman commented 9 years ago

When working with MockFirebase, my application writes to the mocked database. To unit test this code, I would like to look at the same data. When I try to create a new reference explicitly with the pattern

new Firebase('mock://example.firebaseio.com');

(which points to the same data my application does) it does not find the same data. I have to pass the created Firebase node reference from my application to my unit tests. This is unwanted.

I've created a JSFiddle to demonstrate the problem: https://jsfiddle.net/paxpo9yu/

From what I've seen in the source code in the "Testing AngularFire" tutorial, this should not be the case

bendrucker commented 9 years ago

See #84. Unfortunately I don't have time to do anything but ship small bug fixes w/ MockFirebase so this is unlikely to be supported by MF itself.

katowulf commented 9 years ago

The way to accomplish this is to use a service for your Firebase refs, such as:

app.constant('Ref', new Firebase(URL)); // plenty of ways to do this part

Now Ref can be mocked by your test units as you see fit (e.g. replaced by MockFirebase). If you utilize a single ref, the changes to data will be shared.

But really, this is missing the point. MockFirebase is a unit testing tool. It should test small, modular exercises of your code base, not e2e tests or broad things that encompass page activities and sophisticated controller logic.

☃, Kato