I have an if-else condition outside of any function to execute a piece of code, I wrote the corresponding testcase but got an error of an undefined variable. here is the js code & testcase respectively.
if(weburl.indexOf('?webUrl=') >= 0){
weburlParam = weburl.split('?');
walletService.getWalletStatus(weburlParam[1]).then(function(res){
$scope.getWalletRes();
}, function(error){
walletService.redirectToErrorPage();
});
} else {
walletService.getWalletStatus().then(function(res){
$scope.getWalletRes();
}, function(error){
walletService.redirectToErrorPage();
});
}
Testcase
var weburl = {
window:{
location:{
href: "xyz.com?a=b"
}
}
}
console.log(window.location.href);
expect(weburl).toEqual('?weburl=');
expect(walletService.getWalletStatus).toHaveBeenCalled();
expect(walletService.getWalletStatus).toHaveBeenCalledWith(weburl);
Error:
TypeError: undefined is not a constructor (evaluating 'weburl.indexOf('?webUrl=')')
Aucun commentaire:
Enregistrer un commentaire