如何使用Jest对失败的API方案进行单元测试

时间:2020-04-26 08:55:40

标签: reactjs jestjs

这是我下面的样本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} />);
});

0 个答案:

没有答案