mockfirebase icon indicating copy to clipboard operation
mockfirebase copied to clipboard

firebase sdk 3.0 support

Open ciekawy opened this issue 8 years ago • 8 comments

what about new sdk 3.0 support? as there is an official release this would be an interested option

https://firebase.google.com/docs/web/setup

ciekawy avatar Jul 05 '16 13:07 ciekawy

I would also be interested in this or any alternative approach to testing Angular2 apps with AngularFire2. Any plans?

kpgarrod avatar Jul 10 '16 12:07 kpgarrod

+1

aaweb avatar Aug 02 '16 08:08 aaweb

+1

simonajones avatar Aug 17 '16 11:08 simonajones

+1 and we are waiting for this here: https://github.com/firebase/firebase-util/issues/96#issuecomment-232568126 Thanks

Nightbr avatar Aug 20 '16 16:08 Nightbr

@katowulf I wouldn't mind helping out to update this library to support firebase sdk 3.x.x if you can provide feedback on what needs to be changed

I added the following to MockFirebase.override so that it overrides the window.firebase reference. This allows using the new syntax of firebase.database().ref() in both source and tests.

window.firebase = {
  database: function() {
    return {
      ref: function(path) {
        return new window.mockfirebase.MockFirebase(path);
      }
    };
  }
};

I then updated MockFirebase.ref to be a property instead of a function so that it passes the $firebaseUtils.assertValidRef check. Those updates allow the following test to pass:

Source

export default class HomeController {
  constructor($firebaseArray) {
    var ref = firebase.database().ref().child('messages');
    this.messages = $firebaseArray(ref);
    return this;
  }

  submit(message) {
    return this.messages.$add(message);
  }
};

HomeController.$inject = ['$firebaseArray'];

Test

describe('HomeController', function() {
  window.MockFirebase.override();

  var controller;

  beforeEach(function() {
    module('application.home');

    inject(function($controller, $firebaseArray) {
      controller = $controller('HomeController', {
        $firebaseArray: $firebaseArray
      });
    });
  });

  it('should read data from firebase', function() {
    //save some data that our controller will read
    var message = 'message';
    controller.submit(message).then(function() {
      expect(controller.messages).toContain(message);
    });
  });
});

The test above works only because I have the submit function returning a promise and use that to wait for the write to be completed. I tried to make it work by just calling $add then using firebaseRef.flush() to flush the write, however, upon calling flush() I get the error:

Error: No deferred tasks to be flushed

EDIT Attempting to use firebaseRef.autoFlush() results in a test failure:

Expected [  ] to contain 'message'.

soumak77 avatar Aug 31 '16 02:08 soumak77

I was able to get basic support added for firebase sdk 3.x. See https://github.com/katowulf/mockfirebase/pull/112 for more info.

soumak77 avatar Aug 31 '16 11:08 soumak77

Any update on this?

giltotherescue avatar Sep 29 '16 04:09 giltotherescue

I would also be interested in using mockFirebase with the 3.x.x SDK -- It seems that this project is dead now? I'd love to contribute to getting mockFirebase ready

Grantlyk avatar Oct 20 '16 15:10 Grantlyk