如何在 Typescript 中运行多个数据集作为 cypress 上测试用例的参数

问题描述 投票:0回答:1

我想运行带有多个数据装置的测试用例,这些数据装置是由赛普拉斯上的数组对象构建的。如下, 我有错误 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', () => {
        ...
      });
    });
  }
);
typescript mocha.js cypress typescript2.0
1个回答
0
投票
Fixtures.forEach((fixture) => {
describe(`${fixture.name} test`, () => {
  it(`set value ${fixture.sValue}`, () => {
    ...
  });

});

尝试上面的方法。据我了解,您不需要在 foreach 中再次初始化对象。

© www.soinside.com 2019 - 2024. All rights reserved.