mvn test只是通过添加angular-mocks文件抛出htmlunit.ScriptException.如果我删除文件,它运行得很好(当然没有部件依赖于模拟,但它们作为单元测试失败而不是抛出错误).
编辑
我强烈怀疑这是一个htmlunit问题,因为更改< browserVersion>时错误不同:
CHROME给出:
TypeError: Cannot find function attachEvent in object [object
HTMLDocument]. (http://localhost:55408/src/lib/angular.js#1568
)
FIREFOX_3_6给出:
Exception invoking Node.removeEventListener() with arguments [String,
NativeArray,Boolean]
INTERNET_EXPLORER_9给出:
Exception invoking Node.detachEvent() with arguments [String,
NativeArray]
堆栈跟踪(摘录FF):
[ERROR] Failed to execute goal com.github.searls:jasmine-maven-plugin:1.3.1.2:test (default) on project my-jasmine-project: The jasmine-maven-plugin encountered an exception: [ERROR] java.lang.RuntimeException: org.openqa.selenium.WebDriverException: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking Node.removeEventListener() with arguments [String,NativeArray,Boolean] [ERROR] Build info: version: '2.32.0',revision: '6c40c187d01409a5dc3b7f8251859150c8af0bcb',time: '2013-04-09 10:39:28' [ERROR] System info: os.name: 'Mac OS X',os.arch: 'x86_64',os.version: '10.8.4',java.version: '1.6.0_51' [ERROR] Driver info: driver.version: HtmlUnitDriver [ERROR] at com.github.searls.jasmine.runner.SpecRunnerExecutor.execute(SpecRunnerExecutor.java:39) ...
pom.xml(摘录):
<plugin> <groupId>com.github.searls</groupId> <artifactId>jasmine-maven-plugin</artifactId> <version>1.3.1.2</version> <configuration> <preloadSources> <source>lib/angular.js</source> <!-- <source>lib/angular-mocks.js</source> --> <source>http://code.angularjs.org/1.1.5/angular-mocks.js</source> </preloadSources> </configuration> <executions> <execution> <goals> <goal>test</goal> </goals> </execution> </executions> </plugin>
将angular-mocks.js添加到test / javascript / lib文件夹并直接从angularjs网站引用它都会产生相同的错误.
解决方法
<preloadSources> <preloadSource>${angular-test-deps}/jQuery.js</preloadSource> <preloadSource>${angular-test-deps}/angular.js</preloadSource> <preloadSource>${angular-test-deps}/angular-mocks.js</preloadSource> </preloadSources>
角度文档声明“Real jQuery总是优先于jqLite,前提是它在DOMContentLoaded事件触发之前加载”(未压缩的1.0.7的第1448行).此修复程序仍然使用CHROME浏览器版本失败,但可以使用FIREFOX_3_6,FIREFOX_17,INTERNET_EXPLORER_9,INTERNET_EXPLORER_8和INTERNET_EXPLORER_7. jasmine-maven-plugin默认为FIREFOX_3_6 borwser版本,因此无需指定浏览器版本.