Skip to content

Commit eeeb594

Browse files
committed
[Switch] Test disabled state with FormControl
1 parent 8652b8e commit eeeb594

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/material-ui/src/Switch/Switch.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect } from 'chai';
33
import { createMount, getClasses } from '@material-ui/core/test-utils';
44
import describeConformance from '../test-utils/describeConformance';
55
import { createClientRender, fireEvent } from 'test/utils/createClientRender';
6+
import FormControl from '../FormControl';
67
import Switch from './Switch';
78

89
describe('<Switch />', () => {
@@ -87,4 +88,50 @@ describe('<Switch />', () => {
8788

8889
expect(getByRole('checkbox')).to.have.property('checked', false);
8990
});
91+
92+
describe('with FormControl', () => {
93+
describe('enabled', () => {
94+
it('should not have the disabled class', () => {
95+
const { getByTestId } = render(
96+
<FormControl>
97+
<Switch data-testid="root" />
98+
</FormControl>,
99+
);
100+
101+
expect(getByTestId('root')).not.to.have.class(classes.disabled);
102+
});
103+
104+
it('should be overridden by props', () => {
105+
const { getByTestId } = render(
106+
<FormControl>
107+
<Switch data-testid="root" disabled />
108+
</FormControl>,
109+
);
110+
111+
expect(getByTestId('root')).to.have.class(classes.disabled);
112+
});
113+
});
114+
115+
describe('disabled', () => {
116+
it('should have the disabled class', () => {
117+
const { getByTestId } = render(
118+
<FormControl disabled>
119+
<Switch data-testid="root" />
120+
</FormControl>,
121+
);
122+
123+
expect(getByTestId('root')).to.have.class(classes.disabled);
124+
});
125+
126+
it('should be overridden by props', () => {
127+
const { getByTestId } = render(
128+
<FormControl disabled>
129+
<Switch data-testid="root" disabled={false} />
130+
</FormControl>,
131+
);
132+
133+
expect(getByTestId('root')).not.to.have.class(classes.disabled);
134+
});
135+
});
136+
});
90137
});

0 commit comments

Comments
 (0)