In your test file, mock the module function with
import { checkAccess } from '<path to your module file>/checkAccess';
jest.mock('<path to your module file>/checkAccess')
and in your test let the mock return the value with mockReturnValue
:
it('should render "No access"', () => {
checkAccess.mockReturnValue(true); // mock will return true
const { getByText } = render(<App />);
expect(getByText('No access')).toBeInTheDocument();
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…