mocha - AngularJS: testing a service with a persistent rootscope -


i want test angularjs alert service (using mocha , chai):

describe('service', function() {     var alertservice;     var $rootscope;      beforeeach(module('components.services'));     beforeeach(inject(function(_alertservice_, _$rootscope_) {         alertservice = _alertservice_;         $rootscope = _$rootscope_;     }));      describe('alertservice', function() {         it('should start 0 alerts', function() {             $rootscope.should.have.property('alerts').with.length(0);         });          it('should add alert of type danger', function() {             alertservice.add('danger', 'test alert!');             $rootscope.should.have.property('alerts').with.length(1);         });          it('should add alert of type warning', function() {             alertservice.add('warning', 'test alert!');             $rootscope.should.have.property('alerts').with.length(2);         });          it('should close via alert', function() {             var alert = $rootscope.alerts[0];             alert.should.have.property('close');             alert.close();             $rootscope.should.have.property('alerts').with.length(1);         });     }); }); 

however, beforeeach method resetting rootscope before each test (i kinda expected run before each "describe", not each "it"), counting number of alerts doesn't work.

what's best way around this? have multiple asserts within 1 big "it"? i'm quite new unit testing in general , in javascript in particular explanation welcome.

it's resetting rootscope because have declared variable , not injected method...try passing in $rootscope , delete var declaration of it.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -