开玩笑和酶测试不可见的组件

时间:2019-12-16 16:39:03

标签: reactjs jestjs enzyme

我正在使用玩笑和酶来测试一些前端组件, 但我将React Visibility Sensor用作https://www.npmjs.com/package/react-visibility-sensor

但是,如果我这样做

slogan = await shallow(<Slogan data={props.data}/>);

    it('Slogan title', async () => {
    expect(slogan.find('.slogan .row .center-xs h2').text()).toEqual(props.data.slogan_text)   });

isVisible一旦为false,就会进行错误测试,表明不存在。

import React, { useState } from 'react';
import VisibilitySensor from 'react-visibility-sensor';

import './slogan.scss';

function Slogan(props) {
  const [active, setVisibility] = useState(true);
  return (
    <VisibilitySensor
      active={active}
      onChange={isVisible => isVisible && setVisibility(false)}
    >
      {({ isVisible }) => (
        <div className="container-fluid max-width slogan" id="slogan">
          <div
            className={
              isVisible ? 'row content_fade_in_animation_top' : 'vhidden row'
            }
          >
            <div className="col-xs-8 col-xs-offset-2 col-md-4 col-md-offset-0 center-xs start-md">
              <h2>{props.data.slogan_text}</h2>
            </div>

错误:

Method “text” is meant to be run on 1 node. 0 found instead.

      43 |   
      44 |   it('Slogan title', async () => {
    > 45 |     expect(slogan.find('.slogan .row .center-xs h2').text()).toEqual(props.data.slogan_text)
         |                                                      ^
      46 |   });

有人可以帮我吗?

谢谢。

0 个答案:

没有答案