我正在使用摩卡-幻影运行测试。
在运行单元测试时,我没有运行http服务器,因此我的资源无法通过绝对urls (例如:/静态/映像/face.png)获得,并且得到以下输出:
% node_modules/mocha-phantomjs/bin/mocha-phantomjs test/runner/runner.html
test app.Main
✓ should show a command line
1 test complete (79 ms)
Error loading resource file:///static/images/face.png (203). Details: Error opening /static/images/face.png: No such file or directory我的测试:
describe "test app.Main", ->
beforeEach ->
@app = App.Main()
React.renderComponent @app, root[0]
afterEach -> React.unmountComponentAtNode root[0]
it "should show a command line", ->
@cmdForm = root.find("div.header-block").first().find('form')
expect(@cmdForm.length).to.equal 1
expect(@cmdForm.find('div.select2-container ul.select2-choices').length).equal 1测试成功了,但同时我也收到了一些丑陋的错误信息。如何配置phantomJS (或mocha?)忽略加载资源/不显示此错误消息?
发布于 2014-05-10 13:27:12
您必须禁用loadImages默认mocha-phantomjs -s loadImages=false
发布于 2016-03-28 11:08:50
发布于 2014-05-05 18:55:34
您可以使用window.onError(function() {...处理程序来捕获(并吃掉)这些错误。
https://stackoverflow.com/questions/23245547
复制相似问题