Skip to content

Commit

Permalink
Fixes #510 - call onAuth() listeners in $digest scope
Browse files Browse the repository at this point in the history
  • Loading branch information
katowulf committed Dec 17, 2014
1 parent 2339075 commit 3694e15
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/FirebaseAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,12 @@
onAuth: function(callback, context) {
var self = this;

this._ref.onAuth(callback, context);
var fn = this._utils.debounce(callback, context, 0);
this._ref.onAuth(fn);

// Return a method to detach the `onAuth()` callback.
return function() {
self._ref.offAuth(callback, context);
self._ref.offAuth(fn);
};
},

Expand Down
18 changes: 10 additions & 8 deletions tests/unit/FirebaseAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,21 @@ describe('FirebaseAuth',function(){
});

describe('$onAuth()',function(){
it('calls onAuth() on the backing ref with callback and context provided',function(){
function cb(){}
//todo add more testing here after mockfirebase v2 auth is released

it('calls onAuth() on the backing ref', function() {
function cb() {}
var ctx = {};
auth.$onAuth(cb,ctx);
expect(ref.onAuth).toHaveBeenCalledWith(cb, ctx);
auth.$onAuth(cb, ctx);
expect(ref.onAuth).toHaveBeenCalledWith(jasmine.any(Function));
});

it('returns a deregistration function that calls offAuth() on the backing ref with callback and context',function(){
function cb(){}
it('returns a deregistration function that calls offAuth() on the backing ref', function(){
function cb() {}
var ctx = {};
var deregister = auth.$onAuth(cb,ctx);
var deregister = auth.$onAuth(cb, ctx);
deregister();
expect(ref.offAuth).toHaveBeenCalledWith(cb, ctx);
expect(ref.offAuth).toHaveBeenCalledWith(jasmine.any(Function));
});
});

Expand Down

0 comments on commit 3694e15

Please sign in to comment.