2017-08-11 4 views
0

このテストを実行するには何か助けが必要です。私はそれに多くの時間を費やしてきました。カルマ/ジャスミンanglejsファクトリでメソッドを呼び出す方法

だから私は立ち往生して助けが必要ですか?

私はファクトリメソッドを1つしか持たず、カルマから[定義されていない、またはnull参照のプロパティ 'method1'を取得できませんでした。

(function() { 
    'use strict'; 
    var first = function() { 
     var method1 = function() { 
      return 'yes'; 
     }; 
     return { 
      method1: method1 
     }; 
    }; 
    angular.module('app').factory('first', [first]); 
})(); 

ここでは、method1を呼び出す試みがあります。

describe('Test Suite', function() { 

    describe('Factory Test', function() { 
     beforeEach(function() { 
      module('app'); 
     }); 

     var service; 

     //beforeEach(inject(function (_first_) { 
     // service = _first_; 
     //  console.log(JSON.stringify(_first_, null, 4)); 
     //})); 

     beforeEach(inject(function ($injector) { 
      service = $injector.get('first'); 
      console.log(JSON.stringify(service, null, 4)); 
     })); 

     //beforeEach(function() { 
     // angular.mock.inject(function ($injector) { 
     //  service = $injector.get('first'); 
     // }) 
     //}); 

     describe('calling method1', function() { 
      var output = service.method1(); 
      expect(output).toBe('yes'); 
     }); 
    }); 
}); 

とカルマ

からの私の出力
IE 11.0.0 (Windows 10 0.0.0) Test Suite Factory Test calling method1 encountered a declaration exception FAILED 
TypeError: Unable to get property 'method1' of undefined or null reference 
    at Anonymous function (tests/firstTest.spec.js:31:13) 
    at Anonymous function (tests/firstTest.spec.js:30:9) 
    at Anonymous function (tests/firstTest.spec.js:4:5) 
IE 11.0.0 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) (0 secs/0.135 secs) 
IE 11.0.0 (Windows 10 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.14 secs/0.135 secs) 

答えて

0

なんてこった、私の愚かな。

私はit( ""、function(){})を追加するのを忘れていました。

ありがとう

関連する問題