I’m trying to write a test suite for a rather complicated js program with a lot of callbacks going on, and I’m hitting the wall of trying to run two tests within the same file. The first test checks behavior when the server returns an empty address book, the second when there is one address in the book…
/*
* Testing Address Dialogs.
*/
$testStateList = function() { /*snip this is a sub test of assertions both tests need to test, that a select box was correctly built. */ }
$testCountryList = function() { /* ditto */}
/* This might be my problem, I'm trying to reuse this element. I clone it here so that I
* can start each test with a fresh copy
*/
var AddressesInOriginalState = document.getElementById('address').cloneNode(true);
asyncTest( "Empty Address Book", function() {
/*mockjax code here, omitted cause I doubt it's the problem */
/* Attaching a new address div for this test to use */
$('#address').remove();
$('#loading').after(AddressesInOriginalState);
// An ajax call is made here. I'm testing object state after the call. Need to wait a half a second.
TNT.init();
setTimeout(function(){
deepEqual(TNT.addressBook, [], 'Address Book should be an empty array');
ok(!$('#loading').hasClass('Active'));
ok($('#address').hasClass('Active'));
ok(!$('#shippingMethod').hasClass('Active'));
ok(!$('#paymentMethod').hasClass('Active'));
ok($('#address form').hasClass('Changed'));
$testStateList();
$testCountryList();
ok($('#address .addressBook').is(':hidden'));
start();
}, 500);
});
asyncTest( "One Address In Book", function() {
/*
* snip - the only difference between the tests is that the response data they
* receive and the assertions based on that data.
*/
});
What’s frustrating is these tests are atomic, they just cannot run simultaneously because they work on the same DOM object. I tried this guy’s plug in…
But it didn’t help.
Any ideas?