Do you guys have any good examples of testing with firebase mocked? even as 
a service. I'm using it as a service in mine still figuring out how to mock 
it in protractor tests.

On Monday, October 15, 2012 1:52:20 PM UTC-7, [email protected] wrote:
>
> Hi Rob -
>
> Co-founder of Firebase here. Did you get everything working?
>
> We'll release some code on gitHub that helps you get going with a new 
> Angular/Firebase project quickly soon.
>
> James
>
>
>
> On Saturday, October 13, 2012 11:06:53 AM UTC-7, Witold Szczerba wrote:
>>
>> Peter is right, how are you going to test your controller in isolation if 
>> you create collaborators inside?
>> If I were you, I would read the blog of Misko, posts between 2007 and 
>> 2009. All the stuff described there can be applied easily in AngularJS, 
>> guess why ? hehe :-) 
>>
>> Regards,
>> Witold Szczerba
>> 12 paź 2012 17:12, "Peter Bacon Darwin" <[email protected]> 
>> napisał(a):
>>
>>> Don't instantiate things like firebase in your controllers.  Wrap 
>>> Firebase in a service and then inject it into your controllers.
>>> That way, when testing, you can simply inject a dummy firebase instead.
>>> By the way, the reason for you failure is that you are testing an 
>>> asynchronous method but checking for its result before the method has run.
>>> Also, I think you should be asking the injector to provide you with a 
>>> controller rather than instantiating it yourself.
>>> Pete
>>>
>>> On 12 October 2012 15:44, Rob Balfre <[email protected]> wrote:
>>>
>>>> Hi, 
>>>>
>>>> I'm trying to figure out a way to create unit tests that work with 
>>>> AngularJS & Firebase (firebase.com).  Here's a very basic example:
>>>>
>>>> controller.js
>>>>
>>>> function TagListCtrl($scope, $timeout)   {
>>>>     $scope.firebaseRef = new Firebase('
>>>> https://gamma.firebase.com/**myusername**');
>>>>     $scope.ctags = [];
>>>>     
>>>>     $scope.firebaseRef.on('child_added', function(snapshot){
>>>>         var message = snapshot.val();
>>>>         if (message.ctag) {
>>>>             $timeout(function() {
>>>>                 $scope.ctags.push({ ctag:message.ctag });
>>>>             },0);
>>>>         }
>>>>     });
>>>> }
>>>> TagListCtrl.$inject = ['$scope','$timeout'];
>>>>
>>>>
>>>> controllerSpec.js
>>>>
>>>> 'use strict';
>>>>
>>>> /* jasmine specs for controllers go here */
>>>>
>>>> describe('Cohort controllers', function() {
>>>>     describe('TagListCtrl', function() {
>>>>         it('should create "ctags" model with 1 ctag', function() {
>>>>             var scope = {},
>>>>             ctrl = new TagListCtrl(scope);
>>>>             expect(scope.ctags.length).toBe(1);
>>>>         });
>>>>     });
>>>> });
>>>>
>>>>
>>>> jsTestDriver.conf
>>>>
>>>> load:
>>>> ...
>>>> - test/lib/firebase/firebase.js
>>>>
>>>>
>>>> The test fails with the output:
>>>>
>>>> ... controllers TagListCtrl.should create "ctags" model with 1 ctag 
>>>> failed (15.00 ms): Error: Expected 0 to be 1.
>>>> Error: Expected 0 to be 1.
>>>> at null.<anonymous> (test/unit/controllersSpec.js:11:40)
>>>>
>>>>
>>>> The non-test code works fine and returns the one result from Firebase 
>>>> fine. 
>>>>
>>>> Any help would be very welcome!
>>>>
>>>> Thanks,
>>>> Rob
>>>>
>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "AngularJS" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to 
>>>> [email protected].
>>>> Visit this group at http://groups.google.com/group/angular?hl=en.
>>>>  
>>>>  
>>>>
>>>
>>>  -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "AngularJS" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to 
>>> [email protected].
>>> Visit this group at http://groups.google.com/group/angular?hl=en.
>>>  
>>>  
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to