fix(storybook): solve test failures

This commit is contained in:
Kagami Sascha Rosylight 2023-07-12 23:33:05 +02:00
parent 3fde3fbc4d
commit 0ba5edc6aa
2 changed files with 6 additions and 3 deletions

View File

@ -29,11 +29,11 @@ export const Default = {
const canvas = within(canvasElement); const canvas = within(canvasElement);
const a = canvas.getByRole<HTMLAnchorElement>('link'); const a = canvas.getByRole<HTMLAnchorElement>('link');
await expect(a.href).toMatch(/^https?:\/\/.*#test$/); await expect(a.href).toMatch(/^https?:\/\/.*#test$/);
await userEvent.click(a, { button: 2 }); await userEvent.pointer({ keys: '[MouseRight]', target: a });
await tick(); await tick();
const menu = canvas.getByRole('menu'); const menu = canvas.getByRole('menu');
await expect(menu).toBeInTheDocument(); await expect(menu).toBeInTheDocument();
await userEvent.click(a, { button: 0 }); await userEvent.click(a);
a.blur(); a.blur();
await tick(); await tick();
await expect(menu).not.toBeInTheDocument(); await expect(menu).not.toBeInTheDocument();

View File

@ -2,8 +2,9 @@
import { expect } from '@storybook/jest'; import { expect } from '@storybook/jest';
import { userEvent, within } from '@storybook/testing-library'; import { userEvent, within } from '@storybook/testing-library';
import { StoryObj } from '@storybook/vue3'; import { StoryObj } from '@storybook/vue3';
import { i18n } from '@/i18n';
import MkAd from './MkAd.vue'; import MkAd from './MkAd.vue';
import { i18n } from '@/i18n';
import { tick } from '@/scripts/test-utils.js';
const common = { const common = {
render(args) { render(args) {
return { return {
@ -36,6 +37,7 @@ const common = {
const i = buttons[0]; const i = buttons[0];
await expect(i).toBeInTheDocument(); await expect(i).toBeInTheDocument();
await userEvent.click(i); await userEvent.click(i);
await tick();
await expect(a).not.toBeInTheDocument(); await expect(a).not.toBeInTheDocument();
await expect(i).not.toBeInTheDocument(); await expect(i).not.toBeInTheDocument();
buttons = canvas.getAllByRole<HTMLButtonElement>('button'); buttons = canvas.getAllByRole<HTMLButtonElement>('button');
@ -49,6 +51,7 @@ const common = {
await expect(back).toBeInTheDocument(); await expect(back).toBeInTheDocument();
await expect(back).toHaveTextContent(i18n.ts._ad.back); await expect(back).toHaveTextContent(i18n.ts._ad.back);
await userEvent.click(back); await userEvent.click(back);
await tick();
if (reduce) { if (reduce) {
await expect(reduce).not.toBeInTheDocument(); await expect(reduce).not.toBeInTheDocument();
} }