2016-03-01 46 views
0

我正在为通过输入对象循环的函数编写一个chai测试。此代码正常工作。如何用chai.js断言测试多个输入?

they('should return the number of nodes in the graph', function (graph, expected) { 
    expect(graph.numberOfNodes()).to.equal(expected) 
    }, { 
    basic: 6, 
    withNewline: 6, 
    doubleDigits: 13, 
    nonConsecutive: 5 
    }) 

但作为一个练习,我想它写在“断言”的风格。

they('should return the number of nodes in the graph', function(graph, xxxx) { 
    assert.equal((graph.numberOfNodes()), yyyy) 
    }) 

如果我将xxxx留空并为yyyy输入一些数字,则所有输入都会根据该数字进行测试。但是,我当然想要根据正确的输入来测试正确的输出,就像“expect”语法所做的那样。

回答

0

解决了我自己的问题。这是一个简单的句法错误。正确的格式是这样的。

they('should return the number of nodes in the graph', function(graph, results) { 
    assert.equal((graph.numberOfNodes()), results) 
    }, { 
    basic: 6, 
    doubleDigits: 13, 
    nonConsecutive: 5, 
    withNewline: 6 
    })