在我的角度测试中,我一直得到一个Error: Unexpected request: GET 'some/rails/view.html'
我使用konacha进行测试,它使用mocha而不是jasmine。该项目基于Rails应用程序,这也是使用konacha的原因。
下面是一个非常简单的示例测试,用于检查是否在Angular应用程序中定义了控制器:
describe "ShowAccountCtrl", ->
beforeEach angular.mock.module('APP_NAME')
beforeEach inject(($rootScope, $controller) ->
@scope = $rootScope.$new()
@ctrl = $controller 'ShowAccountCtrl',
$scope: @scope
)
it "should be defined", ->
expect(@ctrl).to.not.be.undefined我看过一些关于$httpBackend.when('GET', /\.html$/).passThrough();的东西,但是konacha似乎没有类似于passThrough()的方法
这些问题总是发生在$httpBackend.flush()上。
以前有人攻克过这个问题吗?有没有一种方法可以忽略对rails模板的请求,以便我可以专注于测试控制器的功能?
发布于 2013-08-08 03:24:55
这是因为Konacha不support any integration with Rails views。解决方案是手动加载angular的$templateCache,类似于使用模板with the asset pipeline时必须执行的操作。要实现这一点,您需要使您的测试具有ERB预处理器(例如,some_spec.js.coffee.erb)。
beforeEach inject ($templateCache) ->
template = '/app/templates/view.html'
content = """
<%= IO.read(Rails.root.join('/app/templates/view.html')) %>
"""
$templateCache.put template, contenthttps://stackoverflow.com/questions/16860206
复制相似问题