Skip to content

Commit

Permalink
Permit no payload
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Oct 1, 2015
1 parent 7b90ad6 commit d1f36f4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/dom-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default class DOMRenderer {
if (!card) {
throw new Error(`Cannot render unknown card named ${name}`);
}
if (!payload) {
payload = {};
}
let element = createElement('div');
card.display.setup(element, {}, {name}, payload);
return element;
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/dom-renderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,37 @@ test('renders a mobiledoc with card section', (assert) => {
assert.equal(sectionEl.innerHTML, payload.name);
});

test('renders a mobiledoc with card section and no payload', (assert) => {
assert.expect(3);
let cardName = 'title-card';
let TitleCard = {
name: cardName,
display: {
setup(element, options, env, setupPayload) {
assert.deepEqual({}, setupPayload);
element.innerHTML = '';
}
}
};
let mobiledoc = {
version: MOBILEDOC_VERSION,
sections: [
[], // markers
[ // sections
[10, cardName]
]
]
};
let rendered = renderer.render(mobiledoc, document.createElement('div'), {
[cardName]: TitleCard
});
assert.equal(rendered.childNodes.length, 1,
'renders 1 section');
let sectionEl = rendered.childNodes[0];

assert.equal(sectionEl.innerHTML, '');
});

test('renders a mobiledoc with default image section', (assert) => {
assert.expect(3);
let cardName = 'image';
Expand Down

0 comments on commit d1f36f4

Please sign in to comment.