Skip to content

Commit

Permalink
feature/tests — New unit tests for error components
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandat committed Aug 7, 2016
1 parent 12635dd commit f1b6145
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/common/error/show-err.factory.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});

});
16 changes: 16 additions & 0 deletions app/common/error/throw-err.factory.spec.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit f1b6145

Please sign in to comment.