Trying to come up with Karma tests for AngularJS service, but facing some difficulties. Dont know what tests exactly to write. Could anyone help? For example, what should i write for the follwong function:
authorization() {
let t = this;
var authorized = Boolean(localStorage.getItem('authorized'));
var memorizedState = null;
var
clear = function () {
localStorage.removeItem('authorized');
localStorage.removeItem('currentUser');
authorized = false;
memorizedState = null;
t.$state.go('auth');
},
go = function (fallback) {
localStorage.setItem('authorized', 'true');
authorized = true;
var currentUser = localStorage.getItem('currentUser');
var targetState = memorizedState ? memorizedState : fallback;
t.$state.go(targetState);
};
return {
authorized: authorized,
memorizedState: memorizedState,
clear: clear,
go: go
};
}
Aucun commentaire:
Enregistrer un commentaire