2016-03-01 43 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 
    })