我想运行带有多个数据装置的测试用例,这些数据装置是由赛普拉斯上的数组对象构建的。如下, 我有错误 TS2345: 类型为 '(fixture: { name: string; sValue: string; eValue: string}) => void' 的参数不可分配给类型为 '(value: { name: string; sValue: string; eValue: string}, index: number, array: { name: string; sValue: string; eValue: string; }[]) => void'. 有人知道为什么吗?我做错了什么?
const Fixtures = [
{
name: 'name1',
sValue: 'a',
eValue: '1',
},
{
name: 'name2',
sValue: 'b',
eValue: '2',
},
];
Fixtures.forEach(
(fixture: {
name: string;
sValue: string;
eValue: string;
}) => {
describe(`${fixture.name} test`, () => {
it(`set value ${fixture.sValue}`, () => {
...
});
it(`check ${fixture.name} on ${fixture.sValue}`, () => {
...
});
it('check test4', () => {
...
});
it('check testcase 5', () => {
...
});
});
}
);
Fixtures.forEach((fixture) => {
describe(`${fixture.name} test`, () => {
it(`set value ${fixture.sValue}`, () => {
...
});
});
尝试上面的方法。据我了解,您不需要在 foreach 中再次初始化对象。