Skip to content

Commit

Permalink
Resolve issue marko-js#920.
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Nov 15, 2017
1 parent 342a3e7 commit 68129e6
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/morphdom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ function morphdom(
isPrevText = isText;
}

if (endNode === startNode) {
return insertAfter(createMarkerComment(), startNode, parentNode);
}

return endNode;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class {
onMount() {
window.app = this;
}
}

<b key="b"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class {}

-- ${undefined}
23 changes: 23 additions & 0 deletions test/autotests/components-pages/empty-component/template.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
lasso-page dependencies=input.browserDependencies lasso=input.lasso

<!DOCTYPE html>
html lang="en"
head
meta charset="UTF-8"
title -- Marko Test
lasso-head
body

div id="test"
div id="mocha"
div id="testsTarget"

lasso-body

<a key="a"/>

init-components immediate

lasso-slot name="mocha-run"

browser-refresh
10 changes: 10 additions & 0 deletions test/autotests/components-pages/empty-component/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var path = require('path');
var expect = require('chai').expect;

describe(path.basename(__dirname), function() {
it('should allow diffing html', function() {
var app = window.app;
app.forceUpdate();
app.update();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class {
onMount() {
window.app = this;
}
}

<if(input.show)>
<div.show/>
</if>
<else>
<b key="b"/>
</else>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class {}

-- ${undefined}
23 changes: 23 additions & 0 deletions test/autotests/components-pages/if-empty-component/template.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
lasso-page dependencies=input.browserDependencies lasso=input.lasso

<!DOCTYPE html>
html lang="en"
head
meta charset="UTF-8"
title -- Marko Test
lasso-head
body

div id="test"
div id="mocha"
div id="testsTarget"

lasso-body

<a key="a"/>

init-components immediate

lasso-slot name="mocha-run"

browser-refresh
13 changes: 13 additions & 0 deletions test/autotests/components-pages/if-empty-component/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var path = require('path');
var expect = require('chai').expect;

describe(path.basename(__dirname), function() {
it('should allow diffing html', function() {
var app = window.app;
app.forceUpdate();
app.update();
app.input = { show: true };
app.forceUpdate();
app.update();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class {
onMount() {
window.app = this;
}
}

<b model={} key="b"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class {
}

<c key="c"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class {
}

<d key="d1"/>
<d key="d2"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class {
}

<div.d/>
24 changes: 24 additions & 0 deletions test/autotests/components-pages/nesting/template.marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
lasso-page dependencies=input.browserDependencies lasso=input.lasso

<!DOCTYPE html>
html lang="en"
head
meta charset="UTF-8"
title -- Marko Test
lasso-head
body

div id="test"
div id="mocha"
div id="testsTarget"

lasso-body

div id="test-result"
a key="a"

init-components immediate

lasso-slot name="mocha-run"

browser-refresh
16 changes: 16 additions & 0 deletions test/autotests/components-pages/nesting/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var path = require('path');
var expect = require('chai').expect;
var Component = require('./components/a/index.marko');

describe(path.basename(__dirname), function() {
it('should allow diffing html', function() {
var parentNode = document.getElementById('test-result');
var app = window.app;
app.forceUpdate();
app.update();
expect(app.getEl().parentNode).to.equal(parentNode);
expect(parentNode.querySelectorAll('.d').length).to.equal(2);
// Ensure it produces the same output as rendering in the browser.
expect(Component.renderSync().toString(), parentNode.innerHTML)
});
});

0 comments on commit 68129e6

Please sign in to comment.