LoginSignup
TEISHOTOKU-P
@TEISHOTOKU-P (低所得 -P)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

JestでAngularのモジュールのdirective配下のcontrollerが持つ$scope関数をテストしたい

解決したいこと

JestでAngularのモジュールのdirective配下のcontrollerが持つ$scope関数をテストしたい。
下記のようなdirective配下のcontrollerにある$scope関数のテストの仕方が分からないです。
どなたか教えていただきたいです。

var ctrl = angular.module('controllers',[]).config(function($interpololateProvider){
  $interpolateProvider.startSymbol('xxxx');
  $interpolateProvider.endSymbol('xxxx');
}

ctrl.directive('jest', function() {
  return {
    ....
    ....
    ....
    ....
    controller: function($scope, $http) {
        $scope.funcA = function(){
            console.log('this is funcA');
        }
    } 
  }
})

現在の実装

describe('jest funcAのテスト', function () {
    var scope;
    beforeEach(angular.mock.module('ctrl'));
    beforeEach( angular.mock.inject( function( _$rootScope_ , _$controller_ ){
        var $rootScope  = _$rootScope_ ;
        var $controller = _$controller_ ;

        scope   = $rootScope.$new() ;
    } ) ) ;

    it( 'test_funcA' , function() {
        scope.funcA();
        // 今はアサーションしないで置く
    });
});

エラー

scope.funcA is not a function
0

No Answers yet.

Your answer might help someone💌