我一直在进行一些 mocha/chai 测试,除了在每个“it”测试中放置一个循环并一次又一次地迭代之外,我仍然没有找到一种在许多不同的可能性上运行测试的好方法. 问题是,如果我有数十或数百个测试,我不想一遍又一遍地编写相同的 for 循环。
有没有更优雅的方式来做到这一点?特别是使用不同的测试参数一次循环所有测试的测试?
describe('As a dealer, I determine how many cards have been dealt from the deck based on', function(){
console.log(this);
beforeEach(function(){
var deck = new Deck();
var myDeck = deck.getCards();
});
it('the number of cards are left in the deck', function(){
for(var i = 1; i<=52; i++){
myDeck.dealCard();
expect(myDeck.countDeck()).to.equal(52-i);
}
});
it('the number of cards dealt from the deck', function(){
expect(myDeck.countDealt()).to.equal(i);
});
it('the sum of the cards dealt and the cards left in the deck', function(){
expect(myDeck.countDeck() + myDeck.countDealt()).to.equal(52)
});
});