From cf91171f6ced9cec68947f70951a057ae90bd2ce Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Tue, 19 Mar 2024 16:18:11 +0100 Subject: [PATCH] chore(Tooltip): add tests --- test/components/Tooltip.spec.ts | 19 ++++++-- .../__snapshots__/Tooltip.spec.ts.snap | 47 +++++++++++++++++++ 2 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 test/components/__snapshots__/Tooltip.spec.ts.snap diff --git a/test/components/Tooltip.spec.ts b/test/components/Tooltip.spec.ts index f54a1ec2..4c723f50 100644 --- a/test/components/Tooltip.spec.ts +++ b/test/components/Tooltip.spec.ts @@ -1,12 +1,25 @@ +import { defineComponent } from 'vue' import { describe, it, expect } from 'vitest' +import Provider from '../../src/runtime/components/Provider.vue' import Tooltip, { type TooltipProps } from '../../src/runtime/components/Tooltip.vue' import ComponentRender from '../component-render' -describe.skip('Tooltip', () => { +const TooltipWrapper = defineComponent({ + components: { + UProvider: Provider, + UTooltip: Tooltip + }, + inheritAttrs: false, + template: '' +}) + +describe('Tooltip', () => { it.each([ - ['with text', { props: { text: 'Tooltip', open: true }, slots: { default: () => 'Hover me' } }] + ['with text', { props: { text: 'Tooltip', open: true }, slots: { default: () => 'Hover me' } }], + ['with arrow', { props: { text: 'Tooltip', arrow: true, open: true }, slots: { default: () => 'Hover me' } }], + ['with shortcuts', { props: { text: 'Tooltip', shortcuts: ['⌘', 'K'], open: true }, slots: { default: () => 'Hover me' } }] ])('renders %s correctly', async (nameOrHtml: string, options: { props?: TooltipProps, slots?: any }) => { - const html = await ComponentRender(nameOrHtml, options, Tooltip) + const html = await ComponentRender(nameOrHtml, options, TooltipWrapper) expect(html).toMatchSnapshot() }) }) diff --git a/test/components/__snapshots__/Tooltip.spec.ts.snap b/test/components/__snapshots__/Tooltip.spec.ts.snap new file mode 100644 index 00000000..01a0cbd4 --- /dev/null +++ b/test/components/__snapshots__/Tooltip.spec.ts.snap @@ -0,0 +1,47 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`Tooltip > renders with arrow correctly 1`] = ` +"Hover me + + + +
+
Tooltip + Tooltipv-if +
+
+ + +" +`; + +exports[`Tooltip > renders with shortcuts correctly 1`] = ` +"Hover me + + + +
+
Tooltip + Tooltipv-if +
+
+ + +" +`; + +exports[`Tooltip > renders with text correctly 1`] = ` +"Hover me + + + +
+
Tooltip + + Tooltipv-ifv-if +
+
+ + +" +`;