小编And*_* D.的帖子

angular jasmine:'undefined'不是对象 - 在超时内广播 - 错误

我有这样的功能:

 $scope.doIt = function( x, y )
 {
   $timeout( function ()
   {
     $rootScope.$broadcast( 'xxx',
     {
        message: xxx,
        status: xxx
     } );
   } ); 
 }
Run Code Online (Sandbox Code Playgroud)

到目前为止,此功能正常.但在写测试时我遇到了一些麻烦.

describe( 'test doIt function...', function ()
      {
        var $rootScope, $timeout;

        beforeEach( inject( function ( _$rootScope_, _$timeout_ )
        {
          $rootScope = _$rootScope_;
          $timeout = _$timeout_;
          spyOn( $rootScope, '$broadcast' );
          spyOn( scope, 'doIt' ).and.callThrough();
        } ) );

        it( 'test broadcast will be called', inject( function ()
        {
          var testObj = {
            message: 'test1',
            status: 'test2'
          };

          scope.doIt( …
Run Code Online (Sandbox Code Playgroud)

javascript testing jasmine angularjs karma-runner

10
推荐指数
2
解决办法
3622
查看次数

标签 统计

angularjs ×1

jasmine ×1

javascript ×1

karma-runner ×1

testing ×1