vivtony00 / teamform-seed

This project is an application skeleton. It is used for a HKUST Software Engineering Course (COMP3111/H) in Fall 2016/17. My goal: The project is not asking students to re-produce the sample project. We should encourage students to do something better than the TA.
https://course.cse.ust.hk/comp3111/teamform/
MIT License
0 stars 5 forks source link

karma won't recognise firebase function #48

Open bobby414 opened 7 years ago

bobby414 commented 7 years ago

how can we mock or spy on it ...

vivtony00 commented 7 years ago

http://ng-learn.org/2014/08/Testing_Promises_with_Jasmine_Provide_Spy/ there is a website may help

my code is below

     beforeEach(function(){
      module('teamform-app');

            module(function($provide) {
                var user = {uid : "1234"};
                // Fake StoreService Implementation returning a promise
                $provide.value('$firebaseAuth',function(){
                            return {    $createUserWithEmailAndPassword: function(username, password) {return {then: function(callback) {return callback(user);} ,catch:function(callback){return callback("error");}};},
                                                signInWithEmailAndPassword: function(username,password) {return {catch: function(callback) { return callback({message:null}); }};},
                                                $signOut: function() { return null;},
                                                $onAuthStateChanged:function(funct) {funct(user);return user;},
                                                $signInWithPopup:function(way){return {catch: function(callback) { return callback({message:null}); }};}
                                            };
                        }
                );

                $provide.value('$firebaseObject',function(ref){
                            return {
                                $loaded: function() {return {catch: function(callback) {return callback("error");}};}
                            };
                        }
                );
                return null;
            });

      inject(
        function(_$controller_, _$firebaseAuth_, _$firebaseObject_){
          $controller=_$controller_;
                    $firebaseAuth=_$firebaseAuth_;
                    $firebaseObject = _$firebaseObject_
        }
      );
    });

it('emailLogin test', function() { $scope.username="abc@dfe.com"; $scope.password="abcd1234"; $scope.error=null; $scope.firebaseUser=null; spyOn($scope.auth, "signInWithEmailAndPassword").and.callThrough(); $scope.emailLogin(); expect($scope.error).toBeNull(); });