Skip to content
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

firebase sdk 3.0 support #109

Open
ciekawy opened this issue Jul 5, 2016 · 8 comments
Open

firebase sdk 3.0 support #109

ciekawy opened this issue Jul 5, 2016 · 8 comments

Comments

@ciekawy
Copy link

ciekawy commented Jul 5, 2016

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

@kpgarrod
Copy link

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

@aaweb
Copy link

aaweb commented Aug 2, 2016

+1

1 similar comment
@simonajones
Copy link

+1

@Nightbr
Copy link

Nightbr commented Aug 20, 2016

+1 and we are waiting for this here: googlearchive/firebase-util#96 (comment)
Thanks

@soumak77
Copy link

soumak77 commented Aug 31, 2016

@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
Copy link

I was able to get basic support added for firebase sdk 3.x. See #112 for more info.

@giltotherescue
Copy link

Any update on this?

@Grantlyk
Copy link

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

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

8 participants