【问题标题】:Test UseReactiveVar with jest and enzyme用 jest 和酵素测试 UseReactiveVar
【发布时间】:2021-07-06 02:33:17
【问题描述】:

我正在使用 apollo-client-3 进行状态管理。我要测试useReactiveVar

这是我的代码:

import { useReactiveVar } from '@apollo/client';

const showBoxVar = makeVar(false);
const App: FunctionComponent = () => {

    const showBox = useReactiveVar(showBoxVar);
    return (
        <React.Fragment>
            {showBox && <Box/> }

            <SomeComponent />

        </React.Fragment>
    );
}

我想测试一下,一旦 showBox 为真,Box 就会渲染。该怎么做?

【问题讨论】:

    标签: reactjs jestjs enzyme apollo-client


    【解决方案1】:

    你可以像下面这样模拟它们

    jest.mock('@apollo/client', () => {
      return {
        useReactiveVar: () => true,
        makeVar: jest.fn(() => null)
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2020-08-12
      • 2019-08-30
      • 1970-01-01
      • 1970-01-01
      • 2018-07-31
      • 2021-11-22
      • 1970-01-01
      • 2019-12-19
      相关资源
      最近更新 更多