Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit f4f042b

Browse files
author
george
committed
clean up Article component tests
1 parent c118a48 commit f4f042b

File tree

2 files changed

+57
-33
lines changed

2 files changed

+57
-33
lines changed

app/components/Article/__tests__/Article.spec.js

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,75 @@ import Article from "../Article"
33
import Undernet from "undernet"
44
import Prism from "prismjs"
55

6+
jest.mock("app/components/ScrollUpOnMount", () => global.simpleMock("ScrollUpOnMount"))
7+
68
global.scrollTo = jest.fn()
79

8-
jest.mock("undernet", () => ({
9-
start: jest.fn(),
10-
stop: jest.fn(),
11-
}))
10+
const components = ["Tooltips", "Accordions", "Modals", "Dropdowns"]
11+
12+
components.forEach(component => {
13+
Undernet[component].start = jest.fn()
14+
Undernet[component].stop = jest.fn()
15+
})
1216

1317
jest.mock("prismjs", () => ({
1418
highlightAll: jest.fn(),
1519
}))
1620

17-
describe("<Article />", () => {
18-
let wrapper
19-
beforeEach(() => {
20-
const md = "# Test header \n So neat"
21-
wrapper = mount(<Article>{md}</Article>)
22-
})
23-
24-
it("renders", () => {
25-
expect(wrapper).toMatchSnapshot()
26-
})
21+
const mountComponent = () => {
22+
const md = "# Test header \n So neat"
23+
return mount(<Article>{md}</Article>)
24+
}
2725

28-
it("calls window.scrollTo on mount", () => {
29-
expect(window.scrollTo).toHaveBeenCalledWith(0, 0)
30-
})
26+
describe("<Article />", () => {
27+
describe("#render", () => {
28+
it("renders", () => {
29+
// Given
30+
const wrapper = mountComponent()
31+
// Then
32+
expect(wrapper).toMatchSnapshot()
33+
})
3134

32-
it("calls Prism.highlightAll on mount", () => {
33-
expect(Prism.highlightAll).toHaveBeenCalled()
35+
it("sets fadeIn class on wrapper on mount", () => {
36+
// Given
37+
const wrapper = mountComponent()
38+
// Then
39+
const fadeInClassIsPresent = wrapper
40+
.find("article")
41+
.prop("className")
42+
.includes("fadeIn")
43+
expect(fadeInClassIsPresent).toBe(true)
44+
})
3445
})
3546

36-
it("starts Undernet on mount", () => {
37-
expect(Undernet.start).toHaveBeenCalled()
38-
})
47+
describe("#componentWillMount", () => {
48+
it("calls Prism.highlightAll on mount", () => {
49+
// Given
50+
mountComponent()
51+
// Then
52+
expect(Prism.highlightAll).toHaveBeenCalled()
53+
})
3954

40-
it("stops Undernet on unmount", () => {
41-
wrapper.unmount()
42-
expect(Undernet.stop).toHaveBeenCalled()
55+
components.forEach(component => {
56+
it(`calls Undernet.${component}.start`, () => {
57+
// Given
58+
mountComponent()
59+
// Then
60+
expect(Undernet[component].start).toHaveBeenCalled()
61+
})
62+
})
4363
})
4464

45-
it("sets fadeIn class on wrapper on mount", () => {
46-
expect(
47-
wrapper
48-
.find("article")
49-
.prop("className")
50-
.includes("fadeIn")
51-
).toBe(true)
65+
describe("#componentWillUnmount", () => {
66+
components.forEach(component => {
67+
it(`calls Undernet.${component}.stop`, () => {
68+
// Given
69+
const wrapper = mountComponent()
70+
// When
71+
wrapper.unmount()
72+
// Then
73+
expect(Undernet[component].stop).toHaveBeenCalled()
74+
})
75+
})
5276
})
5377
})

app/components/Article/__tests__/__snapshots__/Article.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<Article /> renders 1`] = `
3+
exports[`<Article /> #render renders 1`] = `
44
<Article>
55
<article
66
className="article-wrapper has-no-padding column fadeIn"

0 commit comments

Comments
 (0)