From 13f366426af17bee24a61e281296c0a1f6b0cbbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Tue, 28 May 2019 20:19:30 +0200 Subject: [PATCH 1/2] Fix linting issues --- .../router/programmatic-routing/components/Home.vue | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/__tests__/router/programmatic-routing/components/Home.vue b/tests/__tests__/router/programmatic-routing/components/Home.vue index 75ea8b00..2a794072 100644 --- a/tests/__tests__/router/programmatic-routing/components/Home.vue +++ b/tests/__tests__/router/programmatic-routing/components/Home.vue @@ -1,7 +1,9 @@ @@ -14,4 +16,3 @@ export default { } } - From 99b1e32a2f5190f5153c99c6748963e46f9568a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Fontcuberta?= Date: Tue, 28 May 2019 20:27:48 +0200 Subject: [PATCH 2/2] Use events instead of callback props --- tests/__tests__/components/Button.vue | 11 ++++++----- tests/__tests__/simple-button.js | 11 +++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/__tests__/components/Button.vue b/tests/__tests__/components/Button.vue index 383c1b18..183d4c32 100644 --- a/tests/__tests__/components/Button.vue +++ b/tests/__tests__/components/Button.vue @@ -1,7 +1,7 @@ @@ -12,10 +12,6 @@ export default { type: String, default: '' }, - clicked: { - type: Function, - default: () => true - }, type: { validator: (value) => ['primary', 'secondary'].includes(value), default: 'primary' @@ -28,6 +24,11 @@ export default { } return 'button' } + }, + methods: { + handleClick (e) { + this.$emit('click') + } } } diff --git a/tests/__tests__/simple-button.js b/tests/__tests__/simple-button.js index 6e20ad34..f55bbe21 100644 --- a/tests/__tests__/simple-button.js +++ b/tests/__tests__/simple-button.js @@ -6,18 +6,17 @@ afterEach(cleanup) test('renders button with text', () => { const buttonText = "Click me; I'm sick" const { getByText } = render(SimpleButton, { - props: { text: buttonText, clicked: () => true } + props: { text: buttonText } }) getByText(buttonText) }) -test('clicked prop is called when button is clicked', () => { - const clicked = jest.fn() +test('click event is emitted when button is clicked', () => { const text = 'Click me' - const { getByText } = render(SimpleButton, { - props: { text, clicked } + const { getByText, emitted } = render(SimpleButton, { + props: { text } }) fireEvent.click(getByText(text)) - expect(clicked).toBeCalled() + expect(emitted().click).toHaveLength(1) })