/* eslint-disable no-undef, no-unused-vars, no-native-reassign */
window.__$ = parent.$;
window.__$(function() {
  var _ = parent._;
  var Rx = parent.Rx;
  var chai = parent.chai;
  var assert = chai.assert;
  var tests = parent.tests;
  var common = parent.common;
  var editor = common.editor.getValue();
  // grab the iframe body element
  var body = document.getElementsByTagName('body');
  // change the context of $ so it uses the iFrame for testing
  var $ = __$.proxy(__$.fn.find, __$(body));

  common.runPreviewTests$ =
    function runPreviewTests$({ tests = [], ...rest }) {
      return Rx.Observable.from(tests)
        .map(test => {
          const userTest = {};
          try {
            /* eslint-disable no-eval */
            eval(test);
            /* eslint-enable no-eval */
          } catch (e) {
            userTest.err = e.message.split(':').shift();
          } finally {
            userTest.text = test
              .split(',')
              .pop()
              .replace(/\'/g, '')
              .replace(/\)/, '');
          }
          return userTest;
        })
        .toArray()
        .map(tests => ({ ...rest, tests }));
    };

});

/* eslint-disable no-undef, no-unused-vars, no-native-reassign */
window.__$ = parent.$;
window.__$(function() {
  var _ = parent._;
  var Rx = parent.Rx;
  var chai = parent.chai;
  var assert = chai.assert;
  var tests = parent.tests;
  var common = parent.common;
  var editor = common.editor.getValue();
  // change the context of $ so it uses the iFrame for testing
  var $ = __$.proxy(__$.fn.find, __$(document));

  common.runPreviewTests$ =
    function runPreviewTests$({ tests = [], ...rest }) {
      return Rx.Observable.from(tests)
        .map(test => {
          const userTest = {};
          try {
            /* eslint-disable no-eval */
            eval(test);
            /* eslint-enable no-eval */
          } catch (e) {
            userTest.err = e.message.split(':').shift();
          } finally {
            userTest.text = test
              .split(',')
              .pop()
              .replace(/\'/g, '')
              .replace(/\)/, '');
          }
          return userTest;
        })
        .toArray()
        .map(tests => ({ ...rest, tests }));
    };

});

Fix use the document as the proxy for jquery We proxy the jquery object. This lets us use the jQuery that FCC uses in the iframe.
Fix use the document as the proxy for jquery
We proxy the jquery object. This lets us use the jQuery that FCC
uses in the iframe.

Since jQuery sets the context, the main document object or DOM, at script
load, we need to create a proxy with the context of the iframe,
the document object of the iframe.

This was originally set to the body element. But not all challenges
require a body element.
