katowulf / mockfirebase

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

mockfirebase shares references, not urls #84

Closed SimoneGianni closed 9 years ago

SimoneGianni commented 9 years ago

If I understand correctly, mockfirebase shares data on references, not on urls. So, this code, does not work :

var id = '12345';

new Firebase(baseurl + id).set({test:1});

// then, much much later, inside a component nested in another component that calls another component

function doSomething(id) {
  var ref = new Firebase(Global.baseurl + id);
  ref.on('value', function(ds) {
    console.log(ds.val());  // Will output "null"
  });
}

This does not mimic Firebase behaviour. Even if I could pass references all around, I don't want to tie all layers of the applications to passing Firebase references.

There is an easy naive fix for this, caching mock references inside mockfirebase by url and return them from the constructor if they already exist in the "cache", and it seems like kinda work.

However, is this by design? Or am I missing something on how mockfirebase (or firebase itself) should be used?

bendrucker commented 9 years ago

This is implemented in v1 (#83) and was already requested in #67. v1 allows you to enable caching. I will not be backporting it to 0.x. v1 is at least weeks away.