/* global assert, setup, suite, teardown, test */

suite('inspector', function () {
  setup(function (done) {
    var el = this.sceneEl = document.createElement('a-scene');
    document.body.appendChild(el);

    el.addEventListener('loaded', function () { done(); });
  });

  teardown(function () {
    var el = this.sceneEl;
    el.parentNode.removeChild(el);
  });

  test('adds inspector SCRIPT element to page', function () {
    var el = this.sceneEl;

    // Have to call method directly because Chrome doesn't provide
    // a reliable method for KeyboardEvent
    el.components.inspector.onKeydown({
      keyCode: 73,
      ctrlKey: true,
      altKey: true
    });

    assert.equal(document.querySelectorAll('script[data-name=aframe-inspector]').length, 1);
  });
});

@@ -77,16 +77,79 @@
 on () %7B%0A
+  var SCRIPT_SELECTOR = 'script%5Bdata-name=aframe-inspector%5D';%0A%0A
   setup(
@@ -229,16 +229,140 @@
 cene');%0A
+    // Set a fake URL so the inspector doesn't interfere with other tests%0A    el.setAttribute('inspector', 'url: fake.js');%0A
     docu
@@ -516,36 +516,138 @@
     
-el.parentNode.removeChild(el
+var script = document.querySelector(SCRIPT_SELECTOR);%0A%0A    el.parentNode.removeChild(el);%0A    script.parentNode.removeChild(script
 );%0A 
@@ -753,20 +753,27 @@
  // 
-Have to call
+Must call onKeydown
  met
@@ -982,13 +982,10 @@
 ert.
-equal
+ok
 (doc
@@ -1007,59 +1007,25 @@
 ctor
-All('script%5Bdata-name=aframe-inspector%5D').length, 1
+(SCRIPT_SELECTOR)
 );%0A 

Fix #1862 - Ensure inspector is destroyed upon test completion