我如何重构代码以解决棉绒错误?

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

我一直在为交换案例编写测试案例,有2个测试案例。我收到此皮棉错误消息,提示Update or refactor this function so that its implementation does not duplicate other。由于切换案例包含相似的案例,因此我需要帮助来重新编写我的代码。]

这是我的2例

  it('case 1', () => {
    data = merge(Run.String_Window, {
      0: '3',
    });
    expect(service.getName('year-1', element, frequency)).toEqual(serve);
  });

  it('case 2', () => {
    data = merge(Run.String_Window, {
      0: '5',
    });
    expect(service.getName('year-2', element, frequency)).toEqual(serve);
  });


angular unit-testing refactoring karma-jasmine
1个回答
0
投票
const testCases = [ { desc: 'case 1', input: { /* ... */ }, expected: { /* ... */ } }, { desc: 'case 2', input: { /* ... */ }, expected: { /* ... */ } } // case 3,4,5.... ]; testCases.forEach(tc => { it(tc.desc, () => { //... expect(/*...*/).toEqual(tc.expected); }); });
© www.soinside.com 2019 - 2024. All rights reserved.