简体   繁体   English

如何在角度单位测试中设置html5Mode? 使用业力

[英]how do I set html5Mode in angular unit test? using karma

Ok I have spent a couple hours on this one... 好吧,我已经花了几个小时了...

I cant figure out how to set html5Mode in a angular unit test. 我不知道如何在角度单位测试中设置html5Mode。

Here is my Karma config from my Gruntfile.js. 这是我的Gruntfile.js中的Karma配置。 Gruntfile conf Gruntfile conf

Here is my unit test spec file: Unit Test File (SEE LINE 26) 这是我的单元测试规范文件: 单元测试文件 (请参阅第26行)

So I tried running the unit test from the Angular documentation at [ANgularJS documentation for $location URL here] (section "HTML5 mode") this is the spec file: 因此,我尝试从[此处的$ angular URL的ANgularJS文档](“ HTML5模式”部分)的Angular文档中运行单元测试,这是规范文件:

PASTEBIN DOT COM SLASH SQFr8Y7i PASTEBIN DOT COM SLASH SQFr8Y7i

When I run that ^^ spec file I get this error: 当我运行该^^规格文件时,出现此错误:

Error: [$injector:unpr] Unknown provider: $locationProviderProvider <- $locationProvider

I am trying to make unit tests that test when html5Mode is on and off. 我正在尝试进行html5Mode开启和关闭的单元测试。

You can do it like that : 您可以这样做:

angular.module('testModule', []).config(['$locationProvider',
    function($locationProvider) {
        $locationProvider.html5Mode(true);
}]);

describe('module', function() {

    beforeEach(module(
        'testModule'
    ));

    it('should test url', function() {

    });
});

But do you really need to activate this feature in a unit test ? 但是,您真的需要在单元测试中激活此功能吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM