jeudi 23 juillet 2015

ReferenceError: function is not defined. In Jasmine unitest

I have a function need to test.

         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
                }
            }
        };

And i write unitest for its.

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);

    });

But when i run it, it's shown error: ReferenceError: getPrepaidFieldInfo is not defined

How to check my function and solve this error. Thanks.

Aucun commentaire:

Enregistrer un commentaire