使用陈列室和操纵up在自定义元素中获取文本的问题

时间:2019-05-03 16:26:54

标签: mocha web-component puppeteer

我目前正在使用showroom来测试我的自定义Web组件。假设我有一个简单的hello world组件,其中

// INSIDE HEADER COMPONENT

// Ref to store if there's a resize in progress
const resizeInProgress = useRef(false);

// State to store window size
const [windowSize, setWindowSize] = useState(window.innerWidth);

useEffect(() => {

  // This function trigger the resize event handler
  // And updates the ref saying that there's a resize in progress
  // If theres a resize in progress, it doesn't do anything

  function handleResize() {
    if (resizeInProgress.current === true) {
      return;
    }
    resizeInProgress.current = true;
    throttled_updateWindowSize();
  }

  // This function sets a timeout to update the state with the
  // new window size and when it executes, it resets the
  // resizeInProgress ref to false. You can execute what's the interval
  // You want to handle your resize events, in this case is 1000ms

  function throttled_updateWindowSize() {
    setTimeout(() => {
      console.log("I will be updated!");
      console.log(window.innerWidth);
      setWindowSize(window.innerWidth);
      resizeInProgress.current = false;
    }, 1000);
  }


  window.addEventListener("resize", handleResize);
  return () => window.removeEventListener("resize", handleResize);
}, []);

将输出<hello>James</hello> 。我尝试将hello组件放在span内,以便通过使用Hello Jamesshowroom.find('// span')可以得到文本“ Hello”,但似乎无法得到文本“ James”。有什么我想念的吗?

0 个答案:

没有答案