相关疑难解决方法(0)

运行Karma测试的角度错误:HTML5模式需要<base>标记

我有一个带有Rails后端的单页Angular应用程序.我在我的index.html文件中使用了一个标签,但是当我使用Karma运行我的前端单元测试时,我得到了这个:

$location in HTML5 mode requires a <base> tag to be present
Run Code Online (Sandbox Code Playgroud)

我在我的主.js文件中这样做:

angular.module('my.module').config( function($locationProvider, $routeProvider) {
  $locationProvider.html5Mode( true );
}
Run Code Online (Sandbox Code Playgroud)

那么,有没有什么方法可以<base>在业力实际呈现的页面中注入一个元素?或者,告诉Angular/Karma在运行单元测试时忽略此错误?

更新

这个Google Groups线程这个GitHub问题都描述了这个问题,但在这两种情况下解决方案都是简单地提升Angular的版本.我已经做到了,我甚至可以看到angular-mocks.js默认baseHref设置的行...

这是有问题的规范:

describe 'amnResource', ->
  $compile = null
  $rootScope = null

  beforeEach ->
    module 'ngMock'
    module 'amn'
    module 'directive.template.cache'

    inject([ '$compile', '$rootScope', ($c, $r) ->
      $compile = $c
      $rootScope = $r
    ])

  it 'compiles to an article', ->
    console.log $rootScope
    console.log $rootScope.foo
    $rootScope.foo =
      title: …
Run Code Online (Sandbox Code Playgroud)

angularjs karma-runner

40
推荐指数
3
解决办法
3万
查看次数

标签 统计

angularjs ×1

karma-runner ×1