( function () {
	// Extend QUnit.module to provide a fixture element. This used to be in tests/index.html, but
	// dynamic test runners like Karma build their own web page.
	( function () {
		var orgModule = QUnit.module;

		QUnit.module = function ( name, localEnv ) {
			localEnv = localEnv || {};
			orgModule( name, {
				setup: function () {
					this.fixture = document.createElement( 'div' );
					this.fixture.id = 'qunit-fixture';
					document.body.appendChild( this.fixture );

					if ( localEnv.setup ) {
						localEnv.setup.call( this );
					}
				},
				teardown: function () {
					if ( localEnv.teardown ) {
						localEnv.teardown.call( this );
					}

					this.fixture.parentNode.removeChild( this.fixture );
				}
			} );
		};
	}() );

	/**
	 * Utility for creating iframes.
	 * @return {HTMLElement}
	 */
	QUnit.tmpIframe = function () {
		var iframe = document.createElement( 'iframe' );
		// Will be removed automatically by module teardown
		document.getElementById( 'qunit-fixture' ).appendChild( iframe );
		return iframe;
	};

}() );

( function () {
	// Extend QUnit.module to provide a fixture element. This used to be in tests/index.html, but
	// dynamic test runners like Karma build their own web page.
	( function () {
		var orgModule = QUnit.module;

		QUnit.module = function ( name, localEnv ) {
			localEnv = localEnv || {};
			orgModule( name, {
				beforeEach: function () {
					this.fixture = document.createElement( 'div' );
					this.fixture.id = 'qunit-fixture';
					document.body.appendChild( this.fixture );

					if ( localEnv.name ) {
						localEnv.name.call( this );
					}
				},
				afterEach: function () {
					if ( localEnv.afterEach ) {
						localEnv.afterEach.call( this );
					}

					this.fixture.parentNode.removeChild( this.fixture );
				}
			} );
		};
	}() );

	/**
	 * Utility for creating iframes.
	 * @return {HTMLElement}
	 */
	QUnit.tmpIframe = function () {
		var iframe = document.createElement( 'iframe' );
		// Will be removed automatically by afterEach
		document.getElementById( 'qunit-fixture' ).appendChild( iframe );
		return iframe;
	};

}() );

Fix broken setup/teardown in tests/index.html
tests: Fix broken setup/teardown in tests/index.html

In QUnit 1.16, module setup/teardown was renamed to beforeEach
and afterEach (old names kept for back-compat).

The back-compat aliases were removed in QUnit 2.0.

This didn't break the karma run because we only used setup/teardown
to create an element qunit-fixture for each test, which qunit-karma
does internally for us as well (because that too is a deprecated
feature that was removed long ago).

As such, these setup/teardown handles have been unused for a while
but didn't cause problems unless running tests manually.

Change-Id: I6135706db9c79a2f49279d03fe772bf0a404ff98
