代码之家  ›  专栏  ›  技术社区  ›  edbentley

JEST测试中的静态文件

  •  0
  • edbentley  · 技术社区  · 6 年前

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

    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" .

    有什么关于如何“服务”这样一个静态图像的笑话指导吗?相对于我的测试文件,图像应该位于哪里?

    (注意,我已经添加了 testEnvironmentOptions: { resources: 'usable' } 在笑话中)

    1 回复  |  直到 6 年前
        1
  •  0
  •   edbentley    6 年前

    找到解决方案:设置 testURL 到本地端口,然后将文件 http-server /在那个港口有快车或类似的东西。

    推荐文章