I have a function that needs to be tested.
var getPrepaidFieldInfo = function (field, root) {
if (field === 'PatientDOB') {
return {
fieldName: root.localizedStrings.patientDobLabel,
fieldValue: $filter('date')(new Date(root.principal.patientDob), 'MM/dd/yyyy')
}
}
if (field === 'PatientLastName') {
return {
fieldName: root.localizedStrings.patientLastNameLabel,
fieldValue: root.principal.lastName
}
}
if (field === 'ZipCode') {
return {
fieldName: root.localizedStrings.postalCodeLabel,
fieldValue: root.principal.zipCode
}
}
if (field === 'Client') {
return {
fieldName: root.localizedStrings.clientIdLabel,
fieldValue: root.principal.clientId
}
}
};
Now, I am writing a unit test for it.
it('getPrepaidFieldInfo should work properly', function(){
expect(getPrepaidFieldInfo).toBeDefined();
var field, actual;
field === 'PatientDOB';
spyOn(window.getPrepaidFieldInfo).and.CallThrough();
actual = getPrepaidFieldInfo(field,$rootScope);
expect(actual.fieldName).toEqual($rootScope.localizedStrings.patientDobLabel);
});
However, when I run the test, an error is shown: ReferenceError: getPrepaidFieldInfo is not defined
How can I check my function and resolve this error?