Skip to content

Commit b8a186f

Browse files
ollelauribostromsagirk
authored andcommitted
test: Add tests for TOC component (nodejs#204)
## Description - Adding tests for TOC component
1 parent 49b74ad commit b8a186f

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`TOC component renders correctly 1`] = `
4+
<details
5+
className="toc"
6+
>
7+
<summary>
8+
<h6>
9+
TABLE OF CONTENTS
10+
</h6>
11+
</summary>
12+
<div
13+
dangerouslySetInnerHTML={
14+
Object {
15+
"__html": "mock-toc",
16+
}
17+
}
18+
/>
19+
</details>
20+
`;

test/components/toc.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import renderer from 'react-test-renderer';
3+
import TOC from '../../src/components/toc';
4+
5+
describe('TOC component', () => {
6+
it('renders correctly', () => {
7+
const heading = 'TABLE OF CONTENTS';
8+
const tableOfContents = 'mock-toc';
9+
const tree = renderer
10+
.create(<TOC heading={heading} tableOfContents={tableOfContents} />)
11+
.toJSON();
12+
expect(tree).toMatchSnapshot();
13+
});
14+
it('does not render without a table of contents', () => {
15+
const heading = 'TABLE OF CONTENTS';
16+
const tableOfContents = null;
17+
const tree = renderer.create(
18+
<TOC heading={heading} tableOfContents={tableOfContents} />
19+
);
20+
expect(tree.getInstance()).toBeNull();
21+
});
22+
});

0 commit comments

Comments
 (0)