Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Aug 9, 2024
1 parent fff1250 commit 80c7242
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions packages/mui-base/src/Switch/Root/SwitchRoot.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { act } from '@mui/internal-test-utils';
import { act, screen } from '@mui/internal-test-utils';
import * as Switch from '@base_ui/react/Switch';
import { userEvent } from '@testing-library/user-event';
import { describeConformance, createRenderer } from '#test-utils';
Expand Down Expand Up @@ -58,9 +58,9 @@ describe('<Switch.Root />', () => {
});

it('should update its state if the underlying input is toggled', async () => {
const { getByRole, container } = await render(<Switch.Root />);
const switchElement = getByRole('switch');
const internalInput = container.querySelector('input[type="checkbox"]')! as HTMLInputElement;
await render(<Switch.Root />);
const switchElement = screen.getByRole('switch');
const internalInput = screen.getByRole('checkbox', { hidden: true });

await act(() => {
internalInput.click();
Expand All @@ -72,9 +72,9 @@ describe('<Switch.Root />', () => {

describe('extra props', () => {
it('should override the built-in attributes', async () => {
const { container } = await render(<Switch.Root data-state="checked" role="checkbox" />);
expect(container.firstElementChild as HTMLElement).to.have.attribute('role', 'checkbox');
expect(container.firstElementChild as HTMLElement).to.have.attribute('data-state', 'checked');
await render(<Switch.Root data-state="checked" role="checkbox" data-testid="switch" />);
expect(screen.getByTestId('switch')).to.have.attribute('role', 'checkbox');
expect(screen.getByTestId('switch')).to.have.attribute('data-state', 'checked');
});
});

Expand Down Expand Up @@ -160,8 +160,8 @@ describe('<Switch.Root />', () => {
describe('prop: inputRef', () => {
it('should be able to access the native input', async () => {
const inputRef = React.createRef<HTMLInputElement>();
const { container } = await render(<Switch.Root inputRef={inputRef} />);
const internalInput = container.querySelector('input[type="checkbox"]')!;
await render(<Switch.Root inputRef={inputRef} />);
const internalInput = screen.getByRole('checkbox', { hidden: true });

expect(inputRef.current).to.equal(internalInput);
});
Expand Down Expand Up @@ -247,14 +247,14 @@ describe('<Switch.Root />', () => {
});

it('should place the style hooks on the root and the thumb', async () => {
const { getByRole } = await render(
await render(
<Switch.Root defaultChecked disabled readOnly required>
<Switch.Thumb />
<Switch.Thumb data-testid="thumb" />
</Switch.Root>,
);

const switchElement = getByRole('switch');
const thumb = switchElement.querySelector('span');
const switchElement = screen.getByRole('switch');
const thumb = screen.getByTestId('thumb');

expect(switchElement).to.have.attribute('data-state', 'checked');
expect(switchElement).to.have.attribute('data-disabled', 'true');
Expand All @@ -268,9 +268,8 @@ describe('<Switch.Root />', () => {
});

it('should set the name attribute on the input', async () => {
const { container } = await render(<Switch.Root name="switch-name" />);
const internalInput = container.querySelector('input[type="checkbox"]')! as HTMLInputElement;

await render(<Switch.Root name="switch-name" />);
const internalInput = screen.getByRole('checkbox');
expect(internalInput).to.have.attribute('name', 'switch-name');
});
});

0 comments on commit 80c7242

Please sign in to comment.