diff --git a/app/common/error/show-err.factory.spec.js b/app/common/error/show-err.factory.spec.js new file mode 100644 index 0000000..26621d9 --- /dev/null +++ b/app/common/error/show-err.factory.spec.js @@ -0,0 +1,32 @@ +describe('showErr', function(){ + + var showErr, Err, $cordovaToast, defaultErrMessage; + + beforeEach(inject(function($injector){ + showErr = $injector.get('showErr'); + Err = $injector.get('Err'); + $cordovaToast = $injector.get('$cordovaToast'); + defaultErrMessage = new Err(1002).message; + })); + + it('should render a native toast with message defined in it', function(){ + var err = new Err(2000, {ui:true}); + spyOn($cordovaToast, 'showLongBottom').and.callThrough(); + showErr(err); + expect($cordovaToast.showLongBottom).toHaveBeenCalledWith(err.message); + }); + + it('should render a native toast with a default message', function(){ + var err = new Err(2000); + spyOn($cordovaToast, 'showLongBottom').and.callThrough(); + showErr(err); + expect($cordovaToast.showLongBottom).toHaveBeenCalledWith(defaultErrMessage); + }); + + it('should render a native toast with a default message', function(){ + spyOn($cordovaToast, 'showLongBottom').and.callThrough(); + showErr('some err'); + expect($cordovaToast.showLongBottom).toHaveBeenCalledWith(defaultErrMessage); + }); + +}); diff --git a/app/common/error/throw-err.factory.spec.js b/app/common/error/throw-err.factory.spec.js new file mode 100644 index 0000000..b028fb0 --- /dev/null +++ b/app/common/error/throw-err.factory.spec.js @@ -0,0 +1,16 @@ +describe('throwErr', function(){ + + var throwErr, Err; + + beforeEach(inject(function($injector){ + throwErr = $injector.get('throwErr'); + Err = $injector.get('Err'); + })); + + it('should throw the given err', function(){ + var err = new Err(2000); + var stub = {throwErr: _.wrap(err, throwErr)}; + spyOn(stub, 'throwErr').and.callThrough(); + expect(stub.throwErr).toThrowError(Err); + }); +});