首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >角度测试,使用mocha,意外的请求

角度测试,使用mocha,意外的请求
EN

Stack Overflow用户
提问于 2013-05-31 22:55:37
回答 1查看 905关注 0票数 4

在我的角度测试中,我一直得到一个Error: Unexpected request: GET 'some/rails/view.html'

我使用konacha进行测试,它使用mocha而不是jasmine。该项目基于Rails应用程序,这也是使用konacha的原因。

下面是一个非常简单的示例测试,用于检查是否在Angular应用程序中定义了控制器:

代码语言:javascript
复制
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模板的请求,以便我可以专注于测试控制器的功能?

EN

回答 1

Stack Overflow用户

发布于 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)。

代码语言:javascript
复制
beforeEach inject ($templateCache) ->    
  template = '/app/templates/view.html'
  content = """
  <%= IO.read(Rails.root.join('/app/templates/view.html')) %>
  """  
  $templateCache.put template, content
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16860206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档