【问题标题】:Error on import of mp4 file with Jest使用 Jest 导入 mp4 文件时出错
【发布时间】:2017-03-29 19:14:48
【问题描述】:

在我的 react-native 项目中,我使用 react-native-video 播放 mp4 文件。一切正常,除了当我使用 Jest 运行单元测试时出现错误。

导入 mp4 文件时出现此错误:SyntaxError: Unexpected token ILLEGAL。我想文件中有一个特殊字符,JavaScript 解释器不喜欢它。

我想确保我的视频播放器可以正常工作。有没有办法测试播放器而不会在导入时出现此错误?

【问题讨论】:

    标签: javascript unit-testing react-native mp4 jestjs


    【解决方案1】:

    我建议在你的笑话设置中模拟这个文件 (docs)

    {
      "jest": {
        "moduleNameMapper": {
          "\\.mp4$": "<rootDir>/__mocks__/fileMock.js",
        }
      }
    }
    

    __mocks__/fileMock.js

    module.exports = 'test-file-stub';
    

    【讨论】:

    • 谢谢,我不再收到错误消息了。但是,react-native-video 仍然希望收到一个常数。你知道我该如何测试这个组件吗?
    猜你喜欢
    • 1970-01-01
    • 2019-01-19
    • 2020-08-28
    • 2018-04-24
    • 2019-10-04
    • 2016-10-15
    • 1970-01-01
    • 2018-02-27
    • 1970-01-01
    相关资源
    最近更新 更多