这是我下面的样本jest.mock。我已经通过了API的成功响应方案。
jest.mock('../../API', () => {
return {
getBeyondSla: jest.fn(() => {
let data = {
tickets: [
{
customerName: '3',
date: '2020-01-07 04:56:38 AM',
requestType: 'Testing Type',
ticketId: 'e4323952-7e83-4036-b201-3c4b9f3ad899',
ticketStatus: 1,
},
],
type: 'test',
};
return Promise.resolve(data);
}),
};
});
let MyComponentProps = {
handler: {
viewAllRequest: jest.fn(),
textFormat: jest.fn(),
dateFormatter: jest.fn(),
timeFormatter: jest.fn(),
},
};
test('Test if component is rendering', async () => {
render(<MyComponent {...MyComponentProps} />);
});