diff --git a/client/commonFramework/end.js b/client/commonFramework/end.js
index 7fa85bb830..139f6aad00 100644
--- a/client/commonFramework/end.js
+++ b/client/commonFramework/end.js
@@ -77,7 +77,7 @@ $(document).ready(function() {
.delay(500)
.flatMap(() => common.executeChallenge$())
.subscribe(
- ({ code, tests }) => {
+ ({ tests }) => {
common.displayTestResults(tests);
},
({ err }) => {
diff --git a/client/commonFramework/update-preview.js b/client/commonFramework/update-preview.js
index d6ee1a0743..09af6725fa 100644
--- a/client/commonFramework/update-preview.js
+++ b/client/commonFramework/update-preview.js
@@ -1,4 +1,9 @@
-window.common = (function({ Rx: { Observable }, common = { init: [] } }) {
+window.common = (function(global) {
+ const {
+ Rx: { Observable },
+ common = { init: [] }
+ } = global;
+
var libraryIncludes = `
-
+
@@ -36,10 +41,14 @@ window.common = (function({ Rx: { Observable }, common = { init: [] } }) {
return iFrameScript$
.map(script => ``)
- .doOnNext(script => {
+ .flatMap(script => {
preview.open();
preview.write(libraryIncludes + code + script);
preview.close();
+ return Observable.fromCallback($(preview).ready, $(preview))()
+ .first()
+ // delay is need here for first initial run
+ .delay(50);
})
.map(() => code);
};
diff --git a/client/iFrameScripts.js b/client/iFrameScripts.js
index 5fbf663a11..0a3ad3b5ed 100644
--- a/client/iFrameScripts.js
+++ b/client/iFrameScripts.js
@@ -1,6 +1,6 @@
/* eslint-disable no-undef, no-unused-vars, no-native-reassign */
-window.$ = parent.$;
-window.$(function() {
+window.__$ = parent.$;
+window.__$(function() {
var _ = parent._;
var Rx = parent.Rx;
var chai = parent.chai;
@@ -9,6 +9,10 @@ window.$(function() {
var common = parent.common;
var code = common.editor.getValue();
var editor = common.editor;
+ // 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 }) {