ryan
ryan

Reputation: 6655

Pass a parameter to qunit teardown?

I'd like to call a particular method on an object that I create as part of teardown. This object is usually created for every test in the module. In the example code below, cb.close() must be called before TC.destroy is called. I checked and there are no arguments passed to teardown. Looking for a suggested approach that knows to close that tests cb control before tearing it down.

module('codebooks events', {
    setup: function () {
        if (typeof TC.init !== 'undefined') {
            TC.init({
                effects: false
            });
        }
    }, teardown: function () {
        if (TC.destroy) TC.destroy();
    }
});

test('search complete', function () {
    expect(1);
    var cb = TC.createControl({
        type: 'cb',
        el: $('#control-target')
    });
    stop();
    cb.on('cb:searchComplete', function () {
        ok(true, 'search completed');
        cb.close();
        start();
    });
    cb.tcTrigger('cb:search', { term: 'abc', book: 'dictionary' });
});

test('status updated', function () {
    expect(1);
    var cb = TC.createControl({
        type: 'cb',
        el: $('#control-target')
    });
    stop();
    cb.on('cb:statusUpdate', function () {
        ok(true, 'status updated');
        cb.close();
        start();
    });
    cb.tcTrigger('cb:search', { term: 'abc', book: 'dictionary' });
});

Upvotes: 1

Views: 545

Answers (1)

Konstantin Dinev
Konstantin Dinev

Reputation: 34915

Make the cb variable global. Then call close() on it inside your teardown callback. This question should contain all the QUnit callbacks that you need.

Upvotes: 2

Related Questions