Skip to content

Commit

Permalink
fix: add snapshot with reversed prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrylo Hudym-Levkovych authored and Kyrylo Hudym-Levkovych committed Oct 10, 2023
1 parent 7e382dc commit 687e70a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/Stack/Stack.test.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import React from 'react';
import { render } from '@testing-library/react';
import { mount } from 'enzyme';
import renderer from 'react-test-renderer';

import Stack from './index';

const stackList = ['First', 'Second'];

describe('<Stack />', () => {
describe('correct rendering', () => {
it('renders without props', () => {
const tree = renderer.create((
<Stack>content</Stack>
<Stack>{stackList.map((el) => <div>{el}</div>)}</Stack>
)).toJSON();
expect(tree).toMatchSnapshot();
});
it('renders with the reversed prop', () => {
const { container } = render(
<Stack reversed>
{stackList.reverse().map((el) => <div>{el}</div>)}
</Stack>,
);
expect(container).toMatchSnapshot();
});
it('renders with the vertical direction', () => {
const wrapper = mount(<Stack>Content</Stack>);
expect(wrapper.find('.pgn__vstack').length).toBeGreaterThan(0);
Expand All @@ -27,14 +38,6 @@ describe('<Stack />', () => {
const wrapper = mount(<Stack gap={gap}>Content</Stack>);
expect(wrapper.find('.pgn__vstack').hasClass(`pgn__stack-gap--${gap}`)).toEqual(true);
});
it('renders reversed children with the vertical direction', () => {
const wrapper = mount(<Stack reversed>Content</Stack>);
expect(wrapper.find('.pgn__vstack').hasClass('pgn__stack-reversed')).toEqual(true);
});
it('renders reversed children with the horizontal direction', () => {
const wrapper = mount(<Stack direction="horizontal" reversed>Content</Stack>);
expect(wrapper.find('.pgn__hstack').hasClass('pgn__stack-reversed')).toEqual(true);
});
it('renders with the className prop', () => {
const className = 'className';
const wrapper = mount(<Stack className={className}>Content</Stack>);
Expand Down
22 changes: 21 additions & 1 deletion src/Stack/__snapshots__/Stack.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Stack /> correct rendering renders with the reversed prop 1`] = `
<div>
<div
class="pgn__vstack pgn__stack-reversed"
>
<div>
Second
</div>
<div>
First
</div>
</div>
</div>
`;

exports[`<Stack /> correct rendering renders without props 1`] = `
<div
className="pgn__vstack"
>
content
<div>
First
</div>
<div>
Second
</div>
</div>
`;

0 comments on commit 687e70a

Please sign in to comment.