小编eri*_*oes的帖子

在 jest/enzyme 中测试音频标签本机事件处理程序和方法

我一直无法弄清楚如何从这里的音频元素测试事件侦听器和方法。我无法进入事件处理程序调用的任何一个函数集(setDuration() 或 updateProgress)。而且,我不知道如何嘲笑audioRef.current.play() audioRef.current.duration等等。我附上了显示测试代码覆盖率的图像。目前,只有一个测试要渲染。

我试过这样的事情,但我得到 audioPlayer.timeupdate is not a function

    const map = {};
    audioPlayer.addEventListener = jest.fn((event, callback) => {
      map[event] = callback;
    });
    act(() => {
      audioPlayer.timeupdate();
    });
Run Code Online (Sandbox Code Playgroud)

来自 Audio.js

import PropTypes from "prop-types";
import get from "lodash.get";
import throttle from "lodash.throttle";
import Icon from "../../../components/core/elements/icon/default.jsx";

const AudioFlexPlayer = props => {
  const {
    podcastData,
    overrides: { audioUrl, showPodcastSubLink }
  } = props;

  const audioRef = useRef();
  const barWrapperRef = useRef();

  const [canPlay, setCanPlay] = useState(false);
  const …
Run Code Online (Sandbox Code Playgroud)

audio event-handling reactjs jestjs enzyme

5
推荐指数
0
解决办法
405
查看次数

标签 统计

audio ×1

enzyme ×1

event-handling ×1

jestjs ×1

reactjs ×1