Global teardown fn that empties the div#mock No need to remember to always remove stuff at the end of every test!
diff --git a/test/unit.html b/test/unit.html index 601820c..5cb61cf 100644 --- a/test/unit.html +++ b/test/unit.html
@@ -58,6 +58,7 @@ <div id="mock"></div> <script type="text/javascript"> + teardown(function() { $('#mock').empty(); }); var runner = mocha.run(); if (post_xunit_to) {
diff --git a/test/unit/SupSub.test.js b/test/unit/SupSub.test.js index 1602d6f..45d5a23 100644 --- a/test/unit/SupSub.test.js +++ b/test/unit/SupSub.test.js
@@ -3,9 +3,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); function prayWellFormedPoint(pt) { prayWellFormed(pt.parent, pt[L], pt[R]); }
diff --git a/test/unit/autoOperatorNames.test.js b/test/unit/autoOperatorNames.test.js index eb7c21c..0199ce8 100644 --- a/test/unit/autoOperatorNames.test.js +++ b/test/unit/autoOperatorNames.test.js
@@ -3,9 +3,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); function assertLatex(input, expected) { var result = mq.latex();
diff --git a/test/unit/autosubscript.test.js b/test/unit/autosubscript.test.js index a085ccc..3680d31 100644 --- a/test/unit/autosubscript.test.js +++ b/test/unit/autosubscript.test.js
@@ -6,9 +6,6 @@ controller = mq.__controller; cursor = controller.cursor; }); - teardown(function() { - $(mq.el()).remove(); - }); test('auto subscripting variables', function() { mq.latex('x');
diff --git a/test/unit/backspace.test.js b/test/unit/backspace.test.js index 688d1ba..b76ec52 100644 --- a/test/unit/backspace.test.js +++ b/test/unit/backspace.test.js
@@ -6,9 +6,6 @@ controller = mq.__controller; cursor = controller.cursor; }); - teardown(function() { - $(mq.el()).remove(); - }); function prayWellFormedPoint(pt) { prayWellFormed(pt.parent, pt[L], pt[R]); } function assertLatex(latex) {
diff --git a/test/unit/css.test.js b/test/unit/css.test.js index 56e12d2..4388df6 100644 --- a/test/unit/css.test.js +++ b/test/unit/css.test.js
@@ -12,7 +12,6 @@ assert.equal(mock.scrollHeight, 25); assert.equal(mock.scrollWidth, 25); - $(mq.el()).remove(); $(mock).css({ fontSize: '', height: '', @@ -27,8 +26,6 @@ assert.ok(rootEl.hasClass('mq-empty'), 'Empty root block should have the mq-empty class name.'); assert.ok(rootEl.height() > 0, 'Empty root block height should be above 0.'); - - testEl.remove(); }); test('empty block does not collapse', function() { @@ -38,8 +35,6 @@ assert.ok(numeratorEl.hasClass('mq-empty'), 'Empty numerator should have the mq-empty class name.'); assert.ok(numeratorEl.height() > 0, 'Empty numerator height should be above 0.'); - - testEl.remove(); }); test('test florin spacing', function () { @@ -52,8 +47,6 @@ var mqF = $(mq.el()).find('.mq-f'); var testVal = parseFloat(mqF.css('margin-right')) - parseFloat(mqF.css('margin-left')); assert.ok(testVal > 0, 'this should be truthy') ; - - $(mq.el()).remove(); }); test('unary PlusMinus before separator', function () { @@ -78,8 +71,6 @@ assertUnaryOperator(28, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm1,\pm'); assertBinaryOperator(30, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm1,\pm1\pm'); assertBinaryOperator(33, '(-1,-1-1)-1,(+1;+1+1)+1,(\pm1,\pm1\pm1)\pm'); - - $(mq.el()).remove(); }); test('proper unary/binary within style block', function () { @@ -109,8 +100,6 @@ assertUnaryOperator(2, '\\textcolor{red}{\\class{dummy}{-}}'); assertBinaryOperator(6, '\\textcolor{red}{\\class{dummy}{-}}2\\textcolor{green}{\\class{dummy}{+}}'); - - $(mq.el()).remove(); }); test('operator name spacing e.g. sin x', function() {
diff --git a/test/unit/focusBlur.test.js b/test/unit/focusBlur.test.js index 20b4fbd..8fb1b86 100644 --- a/test/unit/focusBlur.test.js +++ b/test/unit/focusBlur.test.js
@@ -17,9 +17,6 @@ mq2 = MQ.MathField($('<span></span>').appendTo('#mock')[0]); wasUpOutOfCalled = false; }); - teardown(function() { - $(mq.el()).add(mq2.el()).remove(); - }); function triggerUpOutOf(mq) { $(mq.el()).find('textarea').trigger(jQuery.Event('keydown', { which: 38 })); @@ -76,8 +73,6 @@ mq.keystroke('Shift-Left'); setTimeout(function() { assert.equal($(mq.el()).find('textarea').val(), 'd'); - - $(mq.el()).remove(); done(); }); }, 100);
diff --git a/test/unit/latex.test.js b/test/unit/latex.test.js index ab6d925..5801112 100644 --- a/test/unit/latex.test.js +++ b/test/unit/latex.test.js
@@ -133,9 +133,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); suite('.latex(...)', function() { function assertParsesLatex(str, latex) { @@ -251,9 +248,6 @@ inner1 = outer.innerFields[0]; inner2 = outer.innerFields[1]; }); - teardown(function() { - $(outer.el()).remove(); - }); test('initial latex', function() { assert.equal(inner1.latex(), 'x_0+x_1+x_2'); @@ -308,9 +302,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); function testCantParse(title /*, latex...*/) { var latex = [].slice.call(arguments, 1);
diff --git a/test/unit/publicapi.test.js b/test/unit/publicapi.test.js index e4fff58..f3d621d 100644 --- a/test/unit/publicapi.test.js +++ b/test/unit/publicapi.test.js
@@ -56,9 +56,6 @@ setup(function() { mq = MQBasic.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); test('typing \\', function() { mq.typedText('\\'); @@ -81,9 +78,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); test('.revert()', function() { var mq = MQ.MathField($('<span>some <code>HTML</code></span>')[0]); @@ -333,9 +327,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); test('basic', function() { mq.cmd('x'); @@ -421,8 +412,6 @@ mq.typedText(' '); assert.equal(cursor[L].ctrlSeq, '\\ ', 'left of the cursor is ' + cursor[L].ctrlSeq); assert.equal(cursor[R], 0, 'right of the cursor is ' + cursor[R]); - - $(mq.el()).remove(); }); test('space behaves like tab when spaceBehavesLikeTab is true', function() { var opts = { 'spaceBehavesLikeTab': true }; @@ -441,8 +430,6 @@ mq.keystroke('Shift-Spacebar'); assert.equal(cursor[L], 0, 'left cursor is ' + cursor[L]); assert.equal(cursor[R], rootBlock.ends[L], 'parent of rootBlock is ' + cursor[R]); - - $(mq.el()).remove(); }); test('space behaves like tab when globally set to true', function() { MQ.config({ spaceBehavesLikeTab: true }); @@ -457,8 +444,6 @@ mq.keystroke('Spacebar'); assert.equal(cursor.parent, rootBlock, 'cursor in root block'); assert.equal(cursor[R], 0, 'cursor at end of block'); - - $(mq.el()).remove(); }); }); @@ -469,9 +454,6 @@ mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); textarea = $(mq.el()).find('textarea');; }); - teardown(function() { - $(mq.el()).remove(); - }); function assertPaste(paste, latex) { if (arguments.length < 2) latex = paste; mq.latex(''); @@ -513,9 +495,6 @@ { statelessClipboard: true }); textarea = $(mq.el()).find('textarea');; }); - teardown(function() { - $(mq.el()).remove(); - }); function assertPaste(paste, latex) { if (arguments.length < 2) latex = paste; mq.latex(''); @@ -564,9 +543,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); test('fractions', function() { mq.latex('\\frac{1}{x}+\\frac{\\frac{1}{2}}{\\frac{3}{4}}'); @@ -665,9 +641,6 @@ mq = MQ.MathField($('<span></span>').appendTo('#mock')[0], { leftRightIntoCmdGoes: 'up' }); }); - teardown(function() { - $(mq.el()).remove(); - }); test('fractions', function() { mq.latex('\\frac{1}{x}+\\frac{\\frac{1}{2}}{\\frac{3}{4}}'); @@ -750,8 +723,6 @@ mq.cmd('n'); assert.equal(mq.latex(), '\\sum_n^{ }', 'cursor in lower limit'); - - $(mq.el()).remove(); }); test('sum starts with `n=`', function() { var mq = MQ.MathField($('<span>').appendTo('#mock')[0], { @@ -764,8 +735,6 @@ mq.cmd('0'); assert.equal(mq.latex(), '\\sum_{n=0}^{ }', 'cursor after the `n=`'); - - $(mq.el()).remove(); }); test('integral still has empty limits', function() { var mq = MQ.MathField($('<span>').appendTo('#mock')[0], { @@ -778,8 +747,6 @@ mq.cmd('0'); assert.equal(mq.latex(), '\\int_0^{ }', 'cursor in the from block'); - - $(mq.el()).remove(); }); }); @@ -794,8 +761,6 @@ assert.equal(mq.latex(), ''); mq.write('asdf'); mq.select(); - - $(mq.el()).remove(); }); }); @@ -815,8 +780,6 @@ $(mq.el()).find('textarea').trigger({ type: 'keydown', which: '37' }); assert.equal(key, 'Left'); - - $(mq.el()).remove(); }); test('cut is async', function() { var mq = MQ.MathField($('<span>').appendTo('#mock')[0], { @@ -839,8 +802,6 @@ $(mq.el()).find('textarea').trigger('keyup'); assert.equal(count, 1); - - $(mq.el()).remove(); }); }); @@ -868,7 +829,6 @@ assert.equal(mq.latex(), "\\frac{mmmm}{mmxmm}"); filler.remove(); - $(mq.el()).remove(); }); test('target is optional', function() { // Insert filler so that the page is taller than the window so this test is deterministic @@ -892,7 +852,6 @@ assert.equal(mq.latex(), "\\frac{mmmm}{mmxmm}"); filler.remove(); - $(mq.el()).remove(); }); }); @@ -908,8 +867,6 @@ assert.ok(jQuery('.embedded-html').length); assert.equal(mq.text(), "embedded text"); assert.equal(mq.latex(), "embedded latex"); - - $(mq.el()).remove(); }); test('inserts at coordinates', function() { // Insert filler so that the page is taller than the window so this test is deterministic @@ -937,7 +894,6 @@ assert.equal(mq.latex(), "\\frac{mmmm}{mmembedded latexmm}"); filler.remove(); - $(mq.el()).remove(); }); }); @@ -967,7 +923,5 @@ assert.ok(jQuery('.embedded-html').length); assert.equal(mq.text(), "sqrt(embedded text)"); assert.equal(mq.latex(), "\\sqrt{embedded latex}"); - - $(mq.el()).remove(); }); });
diff --git a/test/unit/saneKeyboardEvents.test.js b/test/unit/saneKeyboardEvents.test.js index fe59265..41284ea 100644 --- a/test/unit/saneKeyboardEvents.test.js +++ b/test/unit/saneKeyboardEvents.test.js
@@ -10,10 +10,6 @@ el = $('<textarea>').appendTo('#mock'); }); - teardown(function() { - el.remove(); - }); - test('normal keys', function(done) { var counter = 0; saneKeyboardEvents(el, {
diff --git a/test/unit/text.test.js b/test/unit/text.test.js index 982a5ac..11b2617 100644 --- a/test/unit/text.test.js +++ b/test/unit/text.test.js
@@ -71,21 +71,17 @@ var controller = mq.__controller; var cursor = controller.cursor; - try { - mq.latex('\\text{x}'); + mq.latex('\\text{x}'); - mq.keystroke('Left'); - assertSplit(cursor.jQ, 'x'); + mq.keystroke('Left'); + assertSplit(cursor.jQ, 'x'); - mq.keystroke('Backspace'); - assertSplit(cursor.jQ); + mq.keystroke('Backspace'); + assertSplit(cursor.jQ); - mq.keystroke('Right'); - assertSplit(cursor.jQ); - assert.equal(cursor[L], 0); - } finally { - $(mq.el()).remove(); - } + mq.keystroke('Right'); + assertSplit(cursor.jQ); + assert.equal(cursor[L], 0); }); test('typing $ in a textblock splits it', function() { @@ -93,15 +89,11 @@ var controller = mq.__controller; var cursor = controller.cursor; - try { - mq.latex('\\text{asdf}'); - mq.keystroke('Left Left Left'); - assertSplit(cursor.jQ, 'as', 'df'); + mq.latex('\\text{asdf}'); + mq.keystroke('Left Left Left'); + assertSplit(cursor.jQ, 'as', 'df'); - mq.typedText('$'); - assert.equal(mq.latex(), '\\text{as}\\text{df}'); - } finally { - $(mq.el()).remove(); - } + mq.typedText('$'); + assert.equal(mq.latex(), '\\text{as}\\text{df}'); }); });
diff --git a/test/unit/typing.test.js b/test/unit/typing.test.js index 578af1f..f3c30fe 100644 --- a/test/unit/typing.test.js +++ b/test/unit/typing.test.js
@@ -3,9 +3,6 @@ setup(function() { mq = MQ.MathField($('<span></span>').appendTo('#mock')[0]); }); - teardown(function() { - $(mq.el()).remove(); - }); function prayWellFormedPoint(pt) { prayWellFormed(pt.parent, pt[L], pt[R]); } function assertLatex(latex) { @@ -27,7 +24,6 @@ var mq_basic = MQBasic.MathField($('<span></span>').appendTo('#mock')[0]); mq_basic.typedText('1/2'); assert.equal(mq_basic.latex(), '\\frac{1}{2}'); - $(mq_basic.el()).remove(); }); });
diff --git a/test/unit/updown.test.js b/test/unit/updown.test.js index 667e1a6..783036a 100644 --- a/test/unit/updown.test.js +++ b/test/unit/updown.test.js
@@ -6,9 +6,6 @@ controller = mq.__controller; cursor = controller.cursor; }); - teardown(function() { - $(mq.el()).remove(); - }); test('up/down in out of exponent', function() { controller.renderLatexMath('x^{nm}'); @@ -183,7 +180,5 @@ assert.equal(inner.__controller.cursor.parent, inner.__controller.root); inner.keystroke('Down'); assert.equal(inner.__controller.cursor.parent, inner.__controller.root); - - $(outer.el()).remove(); }); });