Skip to content

Commit 918003f

Browse files
committed
refactor(code-snippet): update test suite for CodeSnippet.Skeleton
1 parent de233aa commit 918003f

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

packages/react/src/components/CodeSnippet/CodeSnippet-test.js packages/react/src/components/CodeSnippet/__tests__/CodeSnippet-test.js

+3-16
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
*/
77

88
import React from 'react';
9-
import CodeSnippet from '../CodeSnippet';
10-
import CodeSnippetSkeleton from '../CodeSnippet/CodeSnippet.Skeleton';
11-
import Copy from '../Copy';
12-
import CopyButton from '../CopyButton';
9+
import CodeSnippet from '../';
10+
import Copy from '../../Copy';
11+
import CopyButton from '../../CopyButton';
1312
import { shallow, mount } from 'enzyme';
1413
import { settings } from 'carbon-components';
1514

@@ -55,15 +54,3 @@ describe('Code Snippet', () => {
5554
});
5655
});
5756
});
58-
59-
describe('CodeSnippetSkeleton', () => {
60-
describe('Renders as expected', () => {
61-
const wrapper = shallow(<CodeSnippetSkeleton type="single" />);
62-
63-
it('Has the expected classes', () => {
64-
expect(wrapper.hasClass(`${prefix}--skeleton`)).toEqual(true);
65-
expect(wrapper.hasClass(`${prefix}--snippet`)).toEqual(true);
66-
expect(wrapper.hasClass(`${prefix}--snippet--single`)).toEqual(true);
67-
});
68-
});
69-
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* Copyright IBM Corp. 2016, 2018
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { render, cleanup } from '@carbon/test-utils/react';
9+
import { settings } from 'carbon-components';
10+
import React from 'react';
11+
import { CodeSnippetSkeleton } from '../';
12+
13+
const { prefix } = settings;
14+
const snippetTypes = ['single', 'multi'];
15+
16+
describe('CodeSnippetSkeleton', () => {
17+
afterEach(cleanup);
18+
19+
describe('automated accessibility testing', () => {
20+
it.each(snippetTypes)(
21+
'should have no Axe violations with type="%s"',
22+
async type => {
23+
const { container } = render(<CodeSnippetSkeleton type={type} />);
24+
await expect(container).toHaveNoAxeViolations();
25+
}
26+
);
27+
28+
it.each(snippetTypes)(
29+
'should have no DAP violations with type="%s"',
30+
async type => {
31+
const { container } = render(<CodeSnippetSkeleton type={type} />);
32+
await expect(container).toHaveNoDAPViolations(
33+
`CodeSnippetSkeleton-${type}`
34+
);
35+
}
36+
);
37+
});
38+
39+
it('should default to type="single"', () => {
40+
const { container } = render(<CodeSnippetSkeleton />);
41+
expect(
42+
container.querySelector(`.${prefix}--snippet--single`)
43+
).toBeInstanceOf(HTMLElement);
44+
});
45+
46+
it('should support a custom `className` on the outer-most element', () => {
47+
const className = 'test';
48+
const { container } = render(<CodeSnippetSkeleton className={className} />);
49+
expect(container.firstChild.classList.contains(className)).toBe(true);
50+
});
51+
});

0 commit comments

Comments
 (0)