2016-05-04 19 views
1

我已经在Github中添加了一个Tealium AngularJS作为我的SPA的凉亭组件。这立即打破了我的单元测试。我不明白为什么它应该仍然使用已经设置了基本href的主文件index.html

当我运行gulp test形式在命令行中,我得到这个错误:

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 11 of 118 SUCCESS (0 secs/0.721 secs) 

    PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 12 of 118 SUCCESS (0 secs/0.73 
    secs) 

    PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 13 of 118 SUCCESS (0 secs/0.741 secs) 

    PhantomJS 1.9.8 (Windows 7 0.0.0) ERROR 

     Error: [$location:noc:/dev/code/new-site-ui] $location in HTML5 mode requires a <c:/dev/code/new-site-ui> tag to be present! 

    http://errors.angularjs.org/1.4.8/$location/noc:/dev/code/new-site-ui 
    at c:/dev/code/new-site-ui/bower_components/angular/angular.js:12197 

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 13 of 118 ERROR (0 secs/0.741 secs) 

PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 13 of 118 ERROR (0.004 secs/0.741 secs) 

[13:03:12] 'test' errored after 3.67 s 
[13:03:12] Error: Failed 1 tests. 

    at c:\dev\code\new-site-ui\gulp\unit-tests.js:41:58 
    at removeAllListeners (c:\dev\code\new-site-ui\node_modules\karma\lib\server.js:336:7) 
    at Server.<anonymous> (c:\dev\code\new-site-ui\node_modules\karma\lib\server.js:347:9) 
    at Server.g (events.js:199:16) 
    at Server.emit (events.js:129:20) 
    at net.js:1421:10 
    at process._tickCallback (node.js:355:11) 

Process finished with exit code 1 

我一直争取与此2天..任何人有一个建议?

+0

如果你问这意味着你拥有了一个''标签, 对? – MaKCbIMKo

+0

是的..在主index.html所有测试运行良好,但是当我添加github lib时,它失败,当它来到它的测试 – Dennis

回答

13

您确定您的HTML <head>中有<base href="/">

为了避免需要一个<base>元素,你可以添加到您的角模块的配置:

$locationProvider.html5Mode({ 
    enabled: true, 
    requireBase: false 
}); 

DOC:https://docs.angularjs.org/error/$location/nobase

+0

我已经尝试过,当然它的作品..但关闭requireBase从我对于抓取您的网站并解析IE9中的相对路径,读取对谷歌不利? – Dennis

+0

有人刚刚建议Jasmine在运行单元测试时可能会创建一个index.html,它可能没有设置基准href? – Dennis

+1

嗯,我不熟悉Jasmine和PhantomJS的相互作用,但如果创建了不同的html文件,您可能需要查找关于如何设置页面元的phantomJS文档。对不起,我忍不住了。 (或者我推荐量角器进行端到端测试,服务单元测试的茉莉花/业力) – floribon