jeudi 27 août 2015

How to execute Jasmine test using AngularJS ? I am getting an error undefined Object How can fix this issue?

I am using Node.js for jasmine test so when i execute test using grunt test command i see an error in command line (Undefined is not an object "evaluating 'process.eKey[0]'"). eKey is mutiselect dropdown once user select the value we are passing id to backend so for test i am using correct id(2102) but its giving an error. Any idea what is happening wrong I am new to Angularjs help will be appreciated.

So far tried code....

main.spec.js

describe('prcsFactory', function(){
    'use strict';

    var $httpBackend,Process;
    beforeEach(module('riskAssessmentApp'));

    beforeEach(inject(function(_$httpBackend_ , prcsFactory) {
        $httpBackend = _$httpBackend_;
        Process = prcsFactory;

    }));
    // make sure no expectations were missed in your tests.
    afterEach(function() {
        $httpBackend.verifyNoOutstandingExpectation();
        $httpBackend.verifyNoOutstandingRequest();
    });

    it('should be able to save process to the database',function(){
      var prcsObj = {
          LongName: "Process unit test 01",
          StatementText: "Process statement test 01",
          eKey: 2102,
          eDescription: "Epcf selected key description test 01",
          ControlFunction: "business segment test 01",
          rhKey: 20001,
          LocationKeyList: 67000,
          EntityKeyList: 3358,
          WorkerKey: -1069,
          Owner: "xyz"
      };

      var promise = Process.saveProcess(prcsObj);
      httpBackend = expectPOST('app/rest/save',prcsObj).respond(200,'success');

      httpBackend.flush();
      promise.then(function(res){
        expect(res.data).toBe('success');
      });
    });

});

Aucun commentaire:

Enregistrer un commentaire