我有一个功能需要测试。
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
}
}
};
我为它写了unitest。
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);
});
但是当我运行它时,它显示错误: ReferenceError: getPrepaidFieldInfo is not defined
如何检查我的功能并解决此错误。