为数据是使用函数生成许多数据的数组的条件编写测试用例



这是mockData文件夹中的函数


export const generateNotificationMockMany = (count) => (
[...new Array(count)].map((index) => ({
'group': `group number ${index}`,
'message': `msg for group number ${index}`,
'datetime': '',
}),
));


这是我一直试图编写的测试用例。数据是从一个文件中导入的,该文件中包含生成mockdata的此函数。我如何为它编写测试用例?基本上,我如何使用循环来访问函数生成的所有数据?

it('renders properly for the many variant', ()=> {
render(<NotificationMenu notifications={notificationsMock}/>)
});

以下选项中的一个解决了您的问题,还是您期望其他选项?

循环测试用例:

const mocks = generateNotificationMockMany(10);
for (let notificationsMock of mocks) {
it(`renders properly for the variant ${notificationsMock}`, ()=> {
render(<NotificationMenu notifications={notificationsMock}/>)
});
}

循环内部测试用例:

const mocks = generateNotificationMockMany(10);
it(`renders properly for the many variant`, ()=> {
for (let notificationsMock of mocks) {
render(<NotificationMenu notifications={notificationsMock}/>)
}
});

最新更新