gpt4 book ai didi

angularjs - AngularJS 和 Jasmine 的模拟问题

转载 作者:行者123 更新时间:2023-12-02 05:21:49 26 4
gpt4 key购买 nike

尝试开始在 angularjs 中进行测试(基于 this ),但似乎无法让模拟正常工作。这是我的 Jasmine 文件:

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

有什么想法吗?

最佳答案

改变这一行

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

以下内容

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

我已将示例 jsfiddle 更新为 CoffeeScript:http://jsfiddle.net/jaimem/5Afbm/2/

关于angularjs - AngularJS 和 Jasmine 的模拟问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13714076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com