import { useState } from 'react';
export function useTabs(initialState: string[]) {
const [tabs] = useState(initialState);
const [activeTab, setActiveTab] = useState(0);
return {
tabs,
activeTab,
setActiveTab,
};
}
我试试这个:
import React from 'react';
import { shallow } from 'enzyme';
import PaymentMethods from '../index';
const mockedSetState = jest.fn();
describe('test PaymentMethods component', () => {
jest.mock('../../../hooks/useTabs', () => ({
useTabs: () => ({
tabs: ['Полная оплата', 'В кредит', 'Подписка'],
activeTab: 0,
setActiveTab: mockedSetState,
}),
}));
it('call mocked set state', () => {
expect(mockedSetState).toHaveBeenCalledWith(1);
});
it('should render PaymentMethods component', () => {
expect(shallow(<PaymentMethods />)).toMatchSnapshot();
});
});
但我有错误:
expect(jest.fn()).toHaveBeenCalledWith(...expected) 预期:1 调用次数:0
测试 PaymentMethods 组件 › 应呈现 PaymentMethods 组件 类型错误:useTabs_1.useTabs 不是函数