Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Add interaction test for use async tracker #89

Merged
merged 5 commits into from
Jun 10, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/workshop/src/stories/UseAsyncTracker.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Meta, StoryObj } from '@storybook/react';
import { userEvent, waitFor, within } from '@storybook/testing-library';
import { expect } from '@storybook/jest';
import { UseAsyncTracker } from './UseAsyncTracker';
import { sleep } from './sleep';

const meta = {
component: UseAsyncTracker,
Expand All @@ -13,6 +14,7 @@ type Story = StoryObj<typeof meta>;

export const Default: Story = {
play: async ({ canvasElement }) => {
await sleep();
Copy link
Owner Author

@zenoplex zenoplex Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Play function was failing without sleep.
I can see the button onClick handler is being called via useEvent.click but maybe it was clicked too fast? Nothing seems to happen on the click event.

This could be an issue with storybook.
storybookjs/storybook#18258

const canvas = within(canvasElement);

expect(canvas.getByTestId('global-count').textContent).toBe(
Expand All @@ -22,7 +24,7 @@ export const Default: Story = {
'Other count: 0'
);

await userEvent.click(canvas.getByText('load other'));
await userEvent.click(canvas.getByText('load other 2'));
await waitFor(() => {
expect(canvas.getByTestId('other-count').textContent).toBe(
'Other count: 1'
Expand Down