So testen Sie mehrere Aufrufe der gleichen Funktion mit verschiedenen params?

Nehme ich eine Funktion wie diese:

function foo () {
    obj.method(1);
    obj.method(2);
    obj.method(3);
}

Um es zu testen möchte ich es in 3 tests (mit Mokka TDD und Sinon):

test('medthod is called with 1', function () {
    var expectation = sinon.mock(obj).expects('method').once().withExactArgs(1);
    foo();
    expectation.verify();
});

test('medthod is called with 2', function () {
    var expectation = sinon.mock(obj).expects('method').once().withExactArgs(2);
    foo();
    expectation.verify();
});

test('medthod is called with 3', function () {
    var expectation = sinon.mock(obj).expects('method').once().withExactArgs(3);
    foo();
    expectation.verify();
});

Mit diesem system sinon schlägt mit "Anruf" - Nachricht auf jedem test.

Habe ich es gelöst Beitritt der Baum-tests in einem:

test('medthod is called with 1, 2 and 3', function () {
    var mock = sinon.mock(obj);
    mock.expects('method').once().withExactArgs(1);
    mock.expects('method').once().withExactArgs(2);
    mock.expects('method').once().withExactArgs(3);
    foo();
    mock.verify();
});

Aber ich möchte drei tests und auch nicht mit drei Behauptungen/Erwartungen.

Wie kann das erreicht werden?

InformationsquelleAutor der Frage Kaizo | 2014-01-16

Schreibe einen Kommentar