katowulf / mockfirebase

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

As per issue #87 #88

Closed ghost closed 8 years ago

ghost commented 8 years ago

Thank you for the quick reply

I am trying to replicate the way Angular Mocks uses httpBackend. My controller fetches data from firebase using $firebaseArray

My intention is to use Mockfirebase to create some data which when my controller tries to fetch should have the same data created using Mock Firebase.... In short the way you'd test using httpBackend

beforeEach(function (){
                window.MockFirebase.override();
                module("emr.scheduling.controllers");
                module("emr.scheduling.services");
                module("emrApp.config");
                module("emr.common.services");

                inject(["$rootScope", "$controller", "$httpBackend",
                    "emr.scheduling.services.fullcalendar","$window",
                    "emr.common.services.firebaseService",
                    function ($rootScope, $controller, $httpBackend,
                        fulCal, $window, firebaseService) {

                    scope = $rootScope.$new();
                    httpBackend = $httpBackend;
                    fullCalendarService = fulCal;
                    window_browser = $window;
                    firebase = firebaseService;
                    createCalendarController = function(){
                        $controller("emr.scheduling.controllers.fullcalendar",
                        {$scope: scope, fulCal:fullCalendarService});
                    };
                }]);

                test_data = [
                    {
                        "title": "Another event2 - Ian",
                        "start": "2015-08-01T04:30:52.045626Z",
                        "end": "2015-08-01T04:45:52.045626Z",
                        "allDay":false,
                        "owner": "Ian"
                    },
                    {
                        "title": "Another event - Short - Brian",
                        "start": "2015-07-02T04:51:52.045626Z",
                        "end": "2015-07-02T04:51:52.045626Z",
                        "allDay":false,
                        "owner": "Brian"
                    }

                ];

            });

            it("should retrieve data from firebase",
                inject(["FIRE_URL", "SCHEDULING_FIREBASE_URL",function (FIRE_URL,uri){

                    //FIRE_URL = my_url.firebaseio.com
                    // uri = /scheduling
                    var ref = window_browser.MockFirebase(FIRE_URL + uri);

                    ref.push(test_data);
                    createCalendarController();
                    ref.flush();
                    expect(scope.eventSources).toEqual(1);
                }])
            );
bendrucker commented 8 years ago

Please don't open new issues. Closed it because it's not a bug/feature request but we can still continue discussion.