Skip to content

Commit

Permalink
test(ArticleToc): addd snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sabertazimi committed Aug 6, 2021
1 parent 3c419ec commit e0e7ab9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/components/Article/ArticleToc.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { create, act } from 'react-test-renderer';
import { render, fireEvent } from '@testing-library/react';
import ArticleToc from './ArticleToc';

describe('ArticleToc', () => {
const toc = 'Post Table of Contents';

test('should render correctly (snapshot)', () => {
const renderer = create(<ArticleToc toc={toc} />);
const tree = renderer.toJSON();
expect(tree).toMatchSnapshot();

const instance = renderer.root;
const tocButton = instance.find((node) => node.type === 'button');
act(() => tocButton.props.onClick());

const expandTree = renderer.toJSON();
expect(expandTree).toMatchSnapshot();
});

test('should expand ToC when clicked', () => {
const { getByRole, getByText } = render(<ArticleToc toc={toc} />);
const tocButton = getByRole('button');

fireEvent.click(tocButton);
expect(getByText(toc)).toBeInTheDocument();
});
});

0 comments on commit e0e7ab9

Please sign in to comment.