2

angularjs (これに基づく) でのテストを開始しようとしていますが、モックが正しく機能していないようです。これが私のジャスミンファイルです:

describe 'FlightsController', ->
  beforeEach module 'surf-air'

  beforeEach inject ($rootScope, $controller) ->
    scope = $rootScope.$new()
    FlightsController = $controller('FlightsController', {scope: scope})

  it 'should work', -> expect(true).toBe(true)

Testacular が吐き出す内容は次のとおりです。

Chrome 23.0 FlightsController should work FAILED
    Error: Unknown provider: $scopeProvider <- $scope
        at Error (<anonymous>)
        at /Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:28:395
        at Object.c [as get] (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:26:180)
        at /Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:28:476
        at c (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:26:180)
        at d (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:26:314)
        at Object.instantiate (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:27:455)
        at /Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:50:239
        at null.<anonymous> (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/test/unit/controllers.js:9:34)
        at Object.d [as invoke] (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/src/js/angular.min.js:27:325)
    Error: Declaration Location
        at window.jasmine.window.inject.angular.mock.inject (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/test/lib/js/angular-mocks.js:1717:25)
        at null.<anonymous> (/Users/chriskun/forge-workspace/surf-air-pilot-mobile/test/unit/controllers.js:6:16)
        at /Users/chriskun/forge-workspace/surf-air-pilot-mobile/test/unit/controllers.js:4:3
        at /Users/chriskun/forge-workspace/surf-air-pilot-mobile/test/unit/controllers.js:18:4
Chrome 23.0: Executed 1 of 1 (1 FAILED) (0.221 secs / 0.04 secs)

これは次のことが原因です。

$controller('FlightsController', {scope: scope})

何か案は?

4

1 に答える 1

5

この行を変更

FlightsController = $controller('FlightsController', {scope: scope})

次へ

FlightsController = $controller('FlightsController', {$scope: scope})

jsfiddle の例を CoffeeScript に更新しました: http://jsfiddle.net/jaimem/5Afbm/2/

于 2012-12-05T00:07:16.980 に答える