Skip to content

Commit

Permalink
Elements without context should not fail
Browse files Browse the repository at this point in the history
When elements are not added to domdom they
will never have a context. These elements should
still work as expected (just without context).
  • Loading branch information
eirikb committed May 4, 2020
1 parent 9e5fd32 commit f10b0f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ export default (dataOrParent, view, orData) => {
for (let [key, value] of eventProps) {
const event = key[2].toLowerCase() + key.slice(3);
element.addEventListener(event, (...args) => {
element.context.parentPathHack = element.parentPath;
if (element.context) {
element.context.parentPathHack = element.parentPath;
}
return value(...args);
});
}
Expand Down
6 changes: 6 additions & 0 deletions test/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1265,3 +1265,9 @@ test('Flags in components are work and cleared', t => {
t.is(document.body.innerHTML, '<div><div>Test is yo. <div>uhm</div></div></div>');
t.is(counter, 2);
});

test('Element with event but not added via domdom', t => {
domdom();
const element = <button onClick={t.pass}>Click me!</button>;
element.click();
});

0 comments on commit f10b0f4

Please sign in to comment.