From 1d16b302be2518a845a6f21f1a428c8f2dc6886f Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 7 Apr 2016 12:14:53 -0700 Subject: [PATCH] wait for render events in markdown test render callback is async, so we have to wait for the render event to fire. --- notebook/tests/notebook/markdown.js | 41 ++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/notebook/tests/notebook/markdown.js b/notebook/tests/notebook/markdown.js index 4a4c8ae29..344cfed3b 100644 --- a/notebook/tests/notebook/markdown.js +++ b/notebook/tests/notebook/markdown.js @@ -62,21 +62,44 @@ casper.notebook_test(function () { } // Test markdown code blocks + - var md_render = function (text) { - var cell = Jupyter.notebook.insert_cell_at_bottom('markdown'); - cell.set_text(text); - cell.render(); - return cell.get_rendered(); + function md_render_test (codeblock, result, message) { + // make a cell and trigger render + casper.thenEvaluate(function (text) { + var cell = Jupyter.notebook.insert_cell_at_bottom('markdown'); + cell.set_text(text); + // signal window._rendered when cell render completes + window._rendered = null; + cell.events.one("rendered.MarkdownCell", function (event, data) { + window._rendered = data.cell.get_rendered(); + }); + cell.render(); + }, {text: codeblock}); + // wait for render to complete + casper.waitFor(function () { + return casper.evaluate(function () { + return window._rendered; + }); + }); + // test after waiting + casper.then(function () { + // get rendered result + var output = casper.evaluate(function () { + var rendered = window._rendered; + delete window._rendered; + return rendered; + }); + // perform test + this.test.assertEquals(output.trim(), result, message); + }); }; var codeblock = '```\nx = 1\n```' var result = '
x = 1\n
' - output = this.evaluate(md_render, {text: codeblock}); - this.test.assertEquals(output.trim(), result, 'Markdown code block no language'); + md_render_test(codeblock, result, 'Markdown code block no language'); codeblock = '```aaaa\nx = 1\n```' result = '
x = 1\n
' - output = this.evaluate(md_render, {text: codeblock}); - this.test.assertEquals(output.trim(), result, 'Markdown code block unknown language'); + md_render_test(codeblock, result, 'Markdown code block unknown language'); });