How to fix the error: SyntaxError: JSON Parse error: Unexpected identifier "undefined"

1

I'm getting the following error when 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 do I have to do to fix this error?

    
asked by anonymous 16.10.2017 / 19:00

0 answers