Skip to content

Commit

Permalink
Test: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Sapegin committed Nov 7, 2018
1 parent 81692cd commit da949e6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 72 deletions.
7 changes: 3 additions & 4 deletions src/client/rsg-components/Preview/Preview.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ afterEach(() => {

it('should unmount Wrapper component', () => {
const actual = mount(<Preview code={code} evalInContext={evalInContext} />, options);
const node = actual.instance().mountNode;

expect(actual).toHaveLength(1);
expect(actual.html()).toMatch('<button');

expect(node.innerHTML).toMatch('<button');
actual.unmount();
expect(actual).toHaveLength(0);
expect(node.innerHTML).toBe('');
});

it('should not not fail when Wrapper wasn’t mounted', () => {
Expand Down
34 changes: 12 additions & 22 deletions src/client/rsg-components/SectionHeading/SectionHeading.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SectionHeadingRenderer from './SectionHeadingRenderer';
describe('SectionHeading', () => {
const FakeToolbar = () => <div>Fake toolbar</div>;

it('should forward slot properties to the toolbar', () => {
test('should forward slot properties to the toolbar', () => {
const actual = shallow(
<SectionHeading id="section" slotName="slot" slotProps={{ foo: 1, bar: 'baz' }} depth={2}>
A Section
Expand All @@ -15,18 +15,18 @@ describe('SectionHeading', () => {
expect(actual).toMatchSnapshot();
});

it('should render a section heading', () => {
const actual = shallow(
test('render a section heading', () => {
const actual = mount(
<SectionHeadingRenderer id="section" href="/section" depth={2} toolbar={<FakeToolbar />}>
A Section
</SectionHeadingRenderer>
);

expect(actual.dive()).toMatchSnapshot();
expect(actual.find('h2')).toMatchSnapshot();
});

it('should render a deprecated section heading', () => {
const actual = shallow(
test('render a deprecated section heading', () => {
const actual = mount(
<SectionHeadingRenderer
id="section"
href="/section"
Expand All @@ -38,25 +38,20 @@ describe('SectionHeading', () => {
</SectionHeadingRenderer>
);

expect(actual.dive()).toMatchSnapshot();
expect(actual.find('h2')).toMatchSnapshot();
});

it('should prevent the heading level from exceeding the maximum allowed by the Heading component', () => {
const actual = shallow(
test('prevent the heading level from exceeding the maximum allowed by the Heading component', () => {
const actual = mount(
<SectionHeadingRenderer id="section" href="/section" depth={7} toolbar={<FakeToolbar />}>
A Section
</SectionHeadingRenderer>
);

expect(
actual
.dive()
.find('Styled(Heading)')
.prop('level')
).toEqual(6);
expect(actual.find('h6')).toHaveLength(1);
});

it('should the href have a parameter id=section', () => {
test('the href have id=section query parameter ', () => {
const actual = shallow(
<SectionHeading
id="section"
Expand All @@ -69,11 +64,6 @@ describe('SectionHeading', () => {
</SectionHeading>
);

expect(
actual
.dive()
.find('SectionHeadingRenderer')
.prop('href')
).toEqual('/?id=section');
expect(actual.prop('href')).toEqual('/?id=section');
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`SectionHeading render a deprecated section heading 1`] = `
<h2
className="rsg--heading-5 rsg--heading2-7"
id="section"
>
<a
className="rsg--sectionName-2 rsg--isDeprecated-3"
href="/section"
>
A Section
</a>
</h2>
`;

exports[`SectionHeading render a section heading 1`] = `
<h2
className="rsg--heading-5 rsg--heading2-7"
id="section"
>
<a
className="rsg--sectionName-2"
href="/section"
>
A Section
</a>
</h2>
`;

exports[`SectionHeading should forward slot properties to the toolbar 1`] = `
<Styled(SectionHeading)
depth={2}
Expand All @@ -20,49 +48,3 @@ exports[`SectionHeading should forward slot properties to the toolbar 1`] = `
A Section
</Styled(SectionHeading)>
`;

exports[`SectionHeading should render a deprecated section heading 1`] = `
<div
className="rsg--wrapper-0"
>
<Styled(Heading)
id="section"
level={2}
>
<a
className="rsg--sectionName-2 rsg--isDeprecated-3"
href="/section"
>
A Section
</a>
</Styled(Heading)>
<div
className="rsg--toolbar-1"
>
<FakeToolbar />
</div>
</div>
`;

exports[`SectionHeading should render a section heading 1`] = `
<div
className="rsg--wrapper-0"
>
<Styled(Heading)
id="section"
level={2}
>
<a
className="rsg--sectionName-2"
href="/section"
>
A Section
</a>
</Styled(Heading)>
<div
className="rsg--toolbar-1"
>
<FakeToolbar />
</div>
</div>
`;

0 comments on commit da949e6

Please sign in to comment.