-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ArticleToc): addd snapshot testing
- Loading branch information
1 parent
3c419ec
commit e0e7ab9
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |