jquery/qunit — Issue #205: QUnit not clearing #qunit-fixture between tests
Author: SimpleAsCouldBe
Created: 2012-03-01 17:49:18+00:00
State: open

The jQuery docs for QUnit make it sound like this should be automatic behavior.

I'm even running tests async to give it time to clear that fixture, but it seems to leave old code in there.

Qunit seems to change test execution order, so it passes every other run (really). That's only because the .clone test doesn't care if other content is in the fixture. The fixture is still polluted every run.

Here are two extensions to Zepto, the test, and the result in the test fixture. You can tell the fixture is bad because it has h2.cloneTestTitle*2 AND h2.outerHtmlTitle, even though those are added in separate tests.

Code:
```javascript

$.fn.clone = function(){
var ret = $();
this.each(function(){
ret.push(this.cloneNode(true));
});
return ret;
};

$.fn.outerHtml = function() {
return $(this).clone().wrap('

').parent().html();
};

```

Test Code:
```javascript
test('$().clone makes a copy of an element', function() {
stop();

var testClass = 'cloneTestTitle'
,	testContent = 'Clone Test Title'
,	html = '

'+ testContent +'

'
,	$elem = $(html)
,	$fixt = $(_fixtureSelector)
;

$fixt.append($elem);
ok($('.' + testClass).length === 1, "Found the test element in the DOM");
$fixt.append($elem.clone());
ok($('.' + testClass).length === 2, "Found the cloned element in the DOM");
debugger;
setTimeout(function() { start(); }, 1000); //give the browser time to do the DOM manipulation
});

test('$().outerHtml returns the full html of an element, not just its contents', function() {
stop();

// Seems to mix up the variables between tests if I don't name them differently
var testOutClass = 'outerHtmlTitle'
,	testOutContent = 'outerHtml Title'
,	outHtml = '

'+ testOutContent +'

'
,	$outElem = $(outHtml)
,	$parentElem = $('

')
,	$fixture = $(_fixtureSelector)
;

$fixture.append($parentElem);
$parentElem.append($outElem);
ok($('.' + testOutClass).length === 1, "Found the test element in the DOM");
notEqual($outElem.html(), $parentElem.html(), 'A parent element\'s .html() is not equal to the child\'s .html()');
equal($outElem.outerHtml(), $parentElem.html(), 'A parent element\'s .html() is equal to the child\'s .outerHtml()');

debugger;
setTimeout(function() { start(); }, 1000); //give the browser time to do the DOM manipulation
});
```

#qunit-fixture contents:
```html

Clone Test Title

outerHtml Title

Clone Test Title

```