1
I am getting the following error while trying to test my function:
Syntaxerror: JSON Parse error: Unexpected Identifier "Undefined"
The function is this:
function onGetInstanceName(e, args) {
rootScope.instance_name = _storage.local.get("instance_name") || _storage[storage].get("instance_name");
rootScope.instanceSelected = JSON.parse(_storage.local.get("instanceSelected")) || JSON.parse(_storage[storage].get("instanceSelected"));
// console.log(rootScope.instanceSelected);
log("info", rootScope.instance_name);
if (null === rootScope.instance_name || '' === rootScope.instance_name) {
log("info", $state.$current.name, ' ', $state.$current.url);
}
rootScope.instance_id = parseInt(_storage[storage].get('instance_id')) || rootScope.instance_id;
rootScope.$broadcast('getOperatorLogged', null);
}
And the test is being done as follows:
it('testing if the onDisplaySelectionInstance function', function(){
srv.onDisplaySelectionInstance();
rootScope.$emit('displaySelectionInstance', null);
});
What I have to do to correct that mistake?
Try to give
console.log
in_storage.local.get("instanceSelected")
and_storage[storage].get("instanceSelected")
, likely that any of them are undefined.– BrTkCa
Before JSON.parse, try to check what’s coming, to see if json is complete.
– Wictor Chaves
@Lucascosta after giving console.log obtained that: _Storage.local.get("instanceSelected") is null and _Storage[Storage]. get("instanceSelected") is Undefined. What I need to do now?
– Aléxia
Do not need to duplicate the comments Alexia, we will see. You need to tell us or find out what they are and why they are null.
– BrTkCa
@Lucascosta has some way I can define it?
– Aléxia
To be honest, what is their origin? In this case what is
_storage
, etc...– BrTkCa