Hi,
I have just started writing two small unit tests.
The first one checks if elements of a list get appended with a container each.
The second one is supposed to check for the existence of a CSS class on a list element when the mouse enters that element. I use the trigger function for this.
In the beginning I just copied the HTML somewhere into the page, and both tests passed.
Then I packed the HTML into the qunit-fixture container, to remove it from sight, and now the second test fails for some reason. It doesn't fail though, if I remove the first test or if I reverse the order of the tests.
Here is the JS code (original order):
- test('loadNavi', function() {
- var $elemsWithSubnav = $('#nav').find('li[id$="Nav"]');
- var idCount = $elemsWithSubnav.length;
- var divCount = $elemsWithSubnav.find('div').length;
- expect(2);
- ok( $('#nav').find('> li').length > 0, "selector returns elements / navigation is present" );
- equals( divCount, idCount, "subnav gets appended to appropriate list elems" );
- });
- test('hoverNavi', function() {
- var $firstNavElem = $('#nav').find('> li:first');
- var enterClass, leaveClass;
- var handler = function(event) {
- if (event.type == 'mouseenter' && $(this).hasClass('over')) {
- enterClass = 'over';
- }
- else if (event.type == 'mouseleave' && !$(this).hasClass('over')) {
- leaveClass = '';
- }
- };
- expect(2);
- $firstNavElem.bind('mouseenter mouseleave', handler);
- $firstNavElem.trigger('mouseenter');
- equals( enterClass, 'over', 'over class added on mouseenter');
- $firstNavElem.trigger('mouseleave');
- equals( leaveClass, '', 'over class removed on mouseleave');
- });
So far I couldn't figure out what the problem is. Anybody?
Thanks!