如何使用AngularJS执行Jasmine测试?我收到错误undefined对象如何解决这个问题?

时间:2015-08-27 16:07:43

标签: angularjs unit-testing jasmine

我使用Node.js进行jasmine测试,所以当我使用grunt test命令执行测试时,我在命令行中看到一个错误(Undefined不是一个对象"评估' process.eKey [0]& #39;&#34)。 eKey是mutiselect下拉列表,一旦用户选择我们将id传递给后端的值,那么测试我使用的是正确的id(2102),但是它给出了一个错误。任何想法发生了什么错误我是Angularjs帮助的新手将不胜感激。

到目前为止尝试过代码......

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

});

0 个答案:

没有答案