unit-testing - 如何通过 mocha-phatomJS 配置资源处理?加载资源文件时出错 :

标签 unit-testing phantomjs mocha.js mocha-phantomjs

我正在使用 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/

相关文章:

ruby-on-rails-3 - 使用 Poltergeist PhantomJS Capybara 驱动程序设置 Cookie

javascript - eslint 应该列在项目的依赖项中,而不是 devDependencies

node.js - 一起运行时 nodejs : Tests pass individually, 失败(mocha、sinon、aws-sdk)

c# - stub 或模拟 ASP.NET Web API HttpClient

javascript - CasperJS(幻影 1.9.7),从昨天开始无法连接 https

python - 在 pydev 中使用 unittest 在 Python 中对整个项目层次结构进行单元测试

单页应用程序的javascript集成测试

javascript - 使用 chai-http 使用 mocha-chai 进行测试期间出现 UnhandledPromiseRejectionWarning

java - 测试字段注入(inject) VS 构造函数注入(inject)

java - TestNG - 构造函数上的@Test