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

如何处理在项目中找到的重复手动模拟

  •  0
  • XYZ  · 技术社区  · 8 年前

    该项目有客户端应用程序和服务器站点代码,一旦项目在本地构建,它将把所有构建的资产(包括前端和后端)放入 build 目录和它包含所有静态资产客户需要使用(所有测试用例也包括在那里)。

    运行后续测试时,jest将引发如下警告消息,因为多个目录中存在重复的手动mock。

    jest-haste-map: duplicate manual mock found:
      Module name: fileMock
      Duplicate Mock path: /Users/x/x/x/x/src/resources/webapp/static/__mocks__/fileMock.js
    This warning is caused by two manual mock files with the same file name.
    Jest will use the mock file found in:
    /Users/x/x/x/x/src/resources/webapp/static/__mocks__/fileMock.js
     Please delete one of the following two files:
     /Users/x/x/x/x/build/classes/webapp/static/__mocks__/fileMock.js
    /Users/x/x/x/x/src/resources/webapp/static/__mocks__/fileMock.js
    
    1 回复  |  直到 8 年前
        1
  •  8
  •   XYZ    8 年前
    "jest": {
        "modulePathIgnorePatterns": [
            "<rootDir>/build"
        ]
    }
    

    添加 build 文件夹到 modulePathIgnorePatterns 在你的内心 package.json 文件。

        2
  •  0
  •   Kirill Groshkov    7 年前

    对我有帮助的是 roots 财产。使测试发现更快。

    https://jestjs.io/docs/en/configuration#roots-array-string