Skip to content

Commit

Permalink
refactor(code-snippet): update test suite for CodeSnippet.Skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblack committed Jan 23, 2020
1 parent de233aa commit 918003f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
*/

import React from 'react';
import CodeSnippet from '../CodeSnippet';
import CodeSnippetSkeleton from '../CodeSnippet/CodeSnippet.Skeleton';
import Copy from '../Copy';
import CopyButton from '../CopyButton';
import CodeSnippet from '../';
import Copy from '../../Copy';
import CopyButton from '../../CopyButton';
import { shallow, mount } from 'enzyme';
import { settings } from 'carbon-components';

Expand Down Expand Up @@ -55,15 +54,3 @@ describe('Code Snippet', () => {
});
});
});

describe('CodeSnippetSkeleton', () => {
describe('Renders as expected', () => {
const wrapper = shallow(<CodeSnippetSkeleton type="single" />);

it('Has the expected classes', () => {
expect(wrapper.hasClass(`${prefix}--skeleton`)).toEqual(true);
expect(wrapper.hasClass(`${prefix}--snippet`)).toEqual(true);
expect(wrapper.hasClass(`${prefix}--snippet--single`)).toEqual(true);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { render, cleanup } from '@carbon/test-utils/react';
import { settings } from 'carbon-components';
import React from 'react';
import { CodeSnippetSkeleton } from '../';

const { prefix } = settings;
const snippetTypes = ['single', 'multi'];

describe('CodeSnippetSkeleton', () => {
afterEach(cleanup);

describe('automated accessibility testing', () => {
it.each(snippetTypes)(
'should have no Axe violations with type="%s"',
async type => {
const { container } = render(<CodeSnippetSkeleton type={type} />);
await expect(container).toHaveNoAxeViolations();
}
);

it.each(snippetTypes)(
'should have no DAP violations with type="%s"',
async type => {
const { container } = render(<CodeSnippetSkeleton type={type} />);
await expect(container).toHaveNoDAPViolations(
`CodeSnippetSkeleton-${type}`
);
}
);
});

it('should default to type="single"', () => {
const { container } = render(<CodeSnippetSkeleton />);
expect(
container.querySelector(`.${prefix}--snippet--single`)
).toBeInstanceOf(HTMLElement);
});

it('should support a custom `className` on the outer-most element', () => {
const className = 'test';
const { container } = render(<CodeSnippetSkeleton className={className} />);
expect(container.firstChild.classList.contains(className)).toBe(true);
});
});

0 comments on commit 918003f

Please sign in to comment.