Open bobby414 opened 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(); });
how can we mock or spy on it ...