Skip to content

Commit

Permalink
Merge pull request #52 from robcresswell/chore/add-failing-click-test
Browse files Browse the repository at this point in the history
fix: apply listeners correctly in functional component
  • Loading branch information
robcresswell authored Sep 10, 2019
2 parents 2420f2f + 3c6da0c commit cafe4cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions __tests__/icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,23 @@ describe('Icon', () => {
it('renders an icon', () => {
expect(icon).toMatchSnapshot();
});

it('listens to a click event', () => {
const clickListener = jest.fn()
const iconWithEvent = mount({
name: 'IconWithEvent',
components: { AndroidIcon },
template: `
<AndroidIcon
@click="clickListener"
/>
`,
methods: {
clickListener,
},
})

iconWithEvent.trigger('click')
expect(clickListener).toBeCalled()
});
});
2 changes: 1 addition & 1 deletion template.mst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:class="[data.class, data.staticClass]"
class="material-design-icon <%title%>-icon"
role="img"
@click="listeners.click ? listeners.click : () => true">
v-on="listeners">
<svg :fill="props.fillColor"
class="material-design-icon__svg"
:width="props.size"
Expand Down

0 comments on commit cafe4cf

Please sign in to comment.