注意资源:我在CoffeeScript中
写的一切,我有一个控制器如下:
angular.module('myApp').controller 'MyController', ($scope, $routeParams, Batch) ->
$scope.$on '$routeChangeSuccess',() ->
Batch.get {batchUuid: $routeParams.batchUuid}, (response) ->
$scope.batch_id = response.id
控制器的批量资源是拉定义如下:
angular.module('myApp').factory 'Batch', ($resource) ->
$resource '/batches/:batchUuid', {}
我对这个路线如下:
$routeProvider.when('/batches/:batchUuid',
{ templateUrl: 'batches-processing.html', controller: 'MyController' })
所以:
- 您参观路线/批次/ 22
- 它采用myController的
- 它触发$ routeChangeSuccess
- 它要求获得批资源女巫从路线
- batchUuid它得到一个JSON响应和assi GNS一个id为$ scope.batch_id
现在我要测试的这款,所以我有一个单元测试如下:
describe 'Controllers', ->
beforeEach module 'myApp'
describe 'MyController', ->
scope = {}
ctrl= {}
beforeEach inject ($rootScope, $controller, Batch, $httpBackend) ->
scope = $rootScope.$new()
ctrl = $controller('MyController', ($scope: scope))
#I imagine I need to use either my injected Batch resource or the httpBackend to fake/expect the ajax call here
it "Gets data from the resource and assigns it to scope",() ->
#How on earth do I test this
我已经看到了使用$ httpBackend.expect('/终点的人。 json').response({id:1})等,但我不能这样做。我的资源URL依赖于来自路由的batchUuid。我怎样才能模拟/伪造/实现一个将模拟路由变化的测试,触发$ routeChangeSuccess,将一个routeParameter传递给资源,执行一个获取资源并测试结果?
我把我的头发拉过来,棱角分明的文档似乎没有掩盖它。
谢谢!
传奇伴侣。只是传说中的。 –
减去一个咖啡标记?嘘。这个问题本身在coffeescript –