Skip to content

Commit

Permalink
add functional component test
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrsh committed Feb 14, 2017
1 parent e2fc175 commit cec165f
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/js/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,49 @@ describe('Custom Render', function() {
});
});

describe('Functional Component', function() {
createTestElement("functional", '<functional-component someprop="{{parentMsg}}"></functional-component><slot-functional-component>Default Slot Content</slot-functional-component>');
Moon.component('functional-component', {
functional: true,
props: ['someprop'],
render: function(h, ctx) {
return h("h1", {class: "functionalComponent"}, null, ctx.data.someprop);
}
});
Moon.component('slot-functional-component', {
functional: true,
render: function(h, ctx) {
return h("h1", {class: "functionalSlotComponent"}, null, ctx.slots.default);
}
});
var functionalApp = new Moon({
el: "#functional",
data: {
parentMsg: "Hello Moon!"
}
});
it('should render HTML', function() {
expect(document.getElementsByClassName("functionalComponent")).to.not.be.null;
});
it('should render with props', function() {
expect(document.getElementsByClassName("functionalComponent")[0].innerHTML).to.equal("Hello Moon!");
});
it('should render when updated', function() {
functionalApp.set('parentMsg', 'Changed');
Moon.nextTick(function() {
expect(document.getElementsByClassName("functionalComponent")[0].innerHTML).to.equal("Changed");
});
});

describe("Slots", function() {
it('should render the default slot', function() {
Moon.nextTick(function() {
expect(document.getElementsByClassName("functionalSlotComponent")[0].innerHTML).to.equal("Default Slot Content");
});
});
});
});


// describe('Component', function() {
// createTestElement("component", '<my-component componentprop="{{parentMsg}}"></my-component>');
Expand Down

0 comments on commit cec165f

Please sign in to comment.