我正在使用 mocha-phantomjs 运行测试.
在运行单元测试时,我没有运行 http 服务器,所以我的资源无法通过绝对 url 访问(例如:/static/images/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?)忽略加载该资源/不显示此错误消息?
最佳答案
您必须禁用 loadImages默认 mocha-phantomjs -s loadImages=false
关于unit-testing - 如何通过 mocha-phatomJS 配置资源处理?加载资源文件时出错 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23245547/