回调函数被读取为对象?

我正在尝试做一些量角器测试,并决定创建一个通用功能来测试多个测试用例

at the top of my todo-spec.js I have the following function:

function bomImport(filePath, numLines, alternates, rejected)
{
  it('should import a BOM with ' + String(numLines) + ' lines.', function()
  {
    var customerSelection = browser.driver.findElement(by.css('select[formcontrolname="customer"]')).findElement(by.css('option[value="AMX|NOVI|MI"]'));
    var projectName = browser.driver.findElement(by.css('input[formcontrolname="project"'));
    var quoteType = browser.driver.findElement(by.css('select[formcontrolname="type')).findElement(by.css('option[value="bid"'));
    var quantities = browser.driver.findElement(by.css('input[formcontrolname="quantitie0"'))
    var fileName = browser.driver.findElement(by.css('input[type="file"'));
    var importedLines = browser.driver.findElement(by.id('imported'));

    customerSelection.click();
    projectName.sendKeys("import Test");
    quoteType.click();
    quantities.sendKeys('100');
    fileName.sendKeys(filePath);
    browser.waitForAngular();

    expect(importedLines.getText()).toEqual(numLines)
  })

  it('should reject ' + String(rejected) + ' lines.', function()
  {
    var rejectedLines = browser.driver.findElement(by.id('rejected'));

    expect(rejectedLines.getText()).toEqual(rejected);
  })

  it('should have ' + String(alternates) + ' alternate components', function() 
  {
    var numAlternates = browser.driver.findElement(by.id('alternates'));

    expect(numAlternates.getText()).toEqual(alternates)
  })

}

and I am implementing the function like this also in todo-spec.js

describe('BOM Import Test 1', bomImport('T1 2599B BOM Reformat 4.xlsx', '1050', '1049','0')); 

当量角器到达这一点时,错误消息

describe expects a function argument; received [object Undefined]

但是据我了解,我正在传递一个函数?所以我对错误有点困惑

评论
蜡笔小新@
蜡笔小新@

在这条线

describe('BOM Import Test 1', bomImport('T1 2599B BOM Reformat 4.xlsx', '1050', '1049','0'));

您执行函数并传递未定义的返回值。

您可以将其发送以描述为参数。然后它将在describe函数的代码中执行。但它不会传递您的参数。

如果您想传递函数,则将是代码

describe('BOM Import Test 1', bomImport);

但它不会收到'T1 2599B BOM Reformat 4.xlsx','1050','1049','0'作为参数

点赞
评论