【问题标题】:Static files in Jest testsJest 测试中的静态文件
【发布时间】:2019-06-13 23:12:36
【问题描述】:

在我正在测试的代码中,我正在创建如下图像:

const image = new Image();
image.addEventListener("load", () => {});
image.addEventListener("error", () => {});
image.src = "hello.png"

当我在浏览器中运行时,我让 webpack 将该图像复制到 dist 目录,它工作正常。然而,开玩笑地我得到了错误Error: Could not load img: "http://localhost/hello.png"

关于如何在 Jest 中“提供”这样的静态图像的任何指导?相对于我的测试文件,该图像应位于何处?

(注意我在开玩笑的配置中添加了testEnvironmentOptions: { resources: 'usable' }

【问题讨论】:

    标签: javascript jestjs jsdom node-canvas


    【解决方案1】:

    找到解决方案:将testURL 设置为本地端口,然后在该端口上使用http-server / express 或其他类似的东西提供文件。

    【讨论】:

      猜你喜欢
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 2018-11-06
      • 2018-03-20
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      相关资源
      最近更新 更多