From bcf2eb9be6c7774040778535e7c62f04d28b158c Mon Sep 17 00:00:00 2001 From: taku-yasaka Date: Sun, 14 Sep 2025 11:51:52 +0000 Subject: [PATCH] test: add an example to use `Transition` --- src/__tests__/components/TransitionSample.vue | 36 ++++++++++++++++ src/__tests__/transition.js | 42 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 src/__tests__/components/TransitionSample.vue create mode 100644 src/__tests__/transition.js diff --git a/src/__tests__/components/TransitionSample.vue b/src/__tests__/components/TransitionSample.vue new file mode 100644 index 0000000..2513e61 --- /dev/null +++ b/src/__tests__/components/TransitionSample.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/src/__tests__/transition.js b/src/__tests__/transition.js new file mode 100644 index 0000000..e8003f6 --- /dev/null +++ b/src/__tests__/transition.js @@ -0,0 +1,42 @@ +import '@testing-library/jest-dom' + +import {fireEvent, render} from '..' + +import TransitionSample from './components/TransitionSample' + +test('shows the text', async () => { + // In Vue Test Utils, the component is stubbed + // by default, but javascript hooks are not supported. + // If you want to test user interactions using javascript hooks, + // you can turn off the component stubbing + // by setting global stubs transition to false. + const {getByRole, findByText} = render(TransitionSample, { + global: { + stubs: { + transition: false, + }, + }, + }) + + // Trigger fade in the text. + await fireEvent.click(getByRole('button', {name: 'toggle'})) + + // If setting transition stubs, this assertion is failed + // because javascript hooks are not called and the text is not changed. + expect(await findByText('Completed.')).toBeVisible() +}) + +test('hides the text', async () => { + // If there is no need to use JavaScript Hooks, + // you can render with the default settings. + const {getByRole, queryByText} = render(TransitionSample) + + // Trigger fade in the text. + const toggleButton = getByRole('button', {name: 'toggle'}) + await fireEvent.click(toggleButton) + + // And trigger fade out the text. + await fireEvent.click(toggleButton) + + expect(queryByText('Now fade out...')).not.toBeVisible() +})