Blanket.js not showing correct statement coverage with QUnit

288 Views Asked by At

I am trying out Blanket.js and QUnit, and have written some tests for a particular function that populates a form and submits it. Here is the function I'm testing:

myObj.populateAndSubmitForm = function (data) {
    var $authToken = $('#AuthToken');
    var $userId = $('#userId');
    var $appState = $('#appState');
    var $form = $('#post');

    $authToken.val(data.payload.authToken);
    $userId.val(data.payload.userId);
    $appState.val(data.payload.appState);
    $form.attr('action', data.payload.url);
    $form.submit();
}

In my qunit tests:

QUnit.test('populateAndSubmitForm', function (assert) {
    var data = {
        payload: {
            authToken: 'awef2314',
            userId: '1234',
            appState: 'neutral',
            url: 'tests.html'
        }
    };

    $('#qunit-fixture').html(html);
    var $authToken = $('#AuthToken');
    var $userId = $('#userId');
    var $appState = $('#appState');
    var $form = $('#post');

    // Prevent the form from actually submitting
    $form.submit(function (e) {
        e.preventDefault();
    });

    // Populate the form now
    myObj.populateAndSubmitForm(data);

    assert.equal($authToken.val(), 'awef2314', 'AuthToken OK');
    assert.equal($userId.val(), '1234', 'userId OK');
    assert.equal($appState.val(), 'neutral', 'appState OK');
    assert.equal($form.attr('action'), 'tests.html', 'action url OK');
});

My tests run and pass fine, however blanket.js reports the myObj.populateAndSubmitForm as not being covered (highlights it in red in the browser).

My guess is this is because I'm testing 'side effects' of the function in the DOM, and not a return statement. Still, it would be nice to be able to show that this function has been covered. Thoughts?

0

There are 0 best solutions below