Open codingedgar opened 2 months ago
Leaving this here in case the sandbox gets deleted
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent, expect } from '@storybook/test';
import { ComponentProps } from 'react';
function Case(props: ComponentProps<'form'>) {
return (
<form {...props}>
<input placeholder="not focusable" />
</form>
);
}
const meta = {
title: 'Case',
component: Case,
parameters: {
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
layout: 'fullscreen',
},
} satisfies Meta<typeof Case>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Enabled: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const input = canvas.getByPlaceholderText('not focusable');
await expect(input).toBeEnabled();
await userEvent.type(input, 'can write');
await expect(canvas.queryByDisplayValue('can write')).toBeInTheDocument();
},
};
export const Disabled: Story = {
args: {
inert: '',
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const input = canvas.getByPlaceholderText('not focusable');
await expect(input).toBeEnabled();
await userEvent.type(input, 'can write');
},
};
export const RedundantTest: Story = {
args: {
inert: '',
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const input = canvas.getByPlaceholderText('not focusable');
await expect(input).toBeEnabled();
await userEvent.type(input, 'can write');
await expect(
canvas.queryByDisplayValue('can write')
).not.toBeInTheDocument();
},
};
export const Expected: Story = {
args: {
inert: '',
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const input = canvas.getByPlaceholderText('not focusable');
// to pass
await expect(input).toBeDisabled();
// to fail
await userEvent.type(input, 'can write');
},
};
Seems like the issue comes from here https://github.com/capricorn86/happy-dom/issues/1422
jsdom has the same issue: https://github.com/jsdom/jsdom/issues/3605
Good catch @codingedgar . Looks like you've already filed it here https://github.com/testing-library/user-event/issues/1215
Describe the bug
when a form is inert tests consider you can write and that it is enabled, they pass when they actually failed.
To Reproduce
https://stackblitz.com/edit/github-h8mbsw?file=src%2Fstories%2FCase.stories.tsx
System
Additional context
No response