SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)

    qUnit/mockjax - running multiple tests.

    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...

    Code javascript:
    /*
     * 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...

    http://blog.nparashuram.com/2012/05/...tially-in.html

    But it didn't help.

    Any ideas?

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Bhueller? Bhueller??

    (I ended up breaking the tests to multiple files for now, but that's somewhat annoying).

  3. #3
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    I'm sure this is probably a daft question, but can't you just create a separate copy of AddressesInOriginalState for each test?

  4. #4
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    I'm sure this is probably a daft question, but can't you just create a separate copy of AddressesInOriginalState for each test?
    EDIT: (reread post). No. That would require rewriting the code to satisfy the test where, in production, there's only going to be one element, ever, and it is identified by a unique id. I suppose I could try to figure out a way to pass the element to the object as an argument... wait.

  5. #5
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,412
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    Isn't it possible to run tests on a node or nodes that are detached from the DOM?

  6. #6
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,034
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by fretburner View Post
    Isn't it possible to run tests on a node or nodes that are detached from the DOM?
    Exactly. I just need to rewrite the class being tested to take the object it is manipulating as a constructor object. Then each instance can be given their own element to work with.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •