Javascript React本机测试-错误:钩子调用无效

Javascript React本机测试-错误:钩子调用无效,javascript,react-native,react-hooks,react-hooks-testing-library,Javascript,React Native,React Hooks,React Hooks Testing Library,我在测试以下代码时遇到问题: import {useEffect} from 'react'; export const useButtonPress = () => { console.log('RANG', 'ccc', 1); useEffect(() => { console.log('RANG', 'ccc', 2); return () => {}; }); } 我有一个简单的测试: describe('useButtonPress',

我在测试以下代码时遇到问题:

import {useEffect} from 'react';
export const useButtonPress = () => {
  console.log('RANG', 'ccc', 1);
  useEffect(() => {
    console.log('RANG', 'ccc', 2);
    return () => {};
  });
}
我有一个简单的测试:

describe('useButtonPress', () => {
  const mockComponentId = '123';
  const mockButtonId = 'btn';
  let uut: any;
  beforeEach(() => {
    uut = require('./useNavigationButtonPress').useNavigationButtonPress
  });
  test.only('unsubscribes on unmount', async () => {
    const mockHandler = jest.fn();
    const {unmount, result} = renderHook(() =>
      uut()
    );
    console.log('RANG', 'result.error', result.error);
    unmount();
  });
量程2从未打印,我得到
结果。错误

[Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
        1. You might have mismatching versions of React and the renderer (such as React DOM)
        2. You might be breaking the Rules of Hooks
        3. You might have more than one copy of React in the same app
        See bla.com for tips about how to debug and fix this problem.]
有什么帮助吗

我检查过了,我有一个
react@16.13.1
版本