|
1 | | -import React from "react" |
2 | | -import ReactDOM from "react-dom" |
3 | | -import ReactDOMServer from "react-dom/server" |
4 | | -import Media from "../Media" |
| 1 | +import React from "react"; |
| 2 | +import ReactDOM from "react-dom"; |
| 3 | +import ReactDOMServer from "react-dom/server"; |
| 4 | +import Media from "../Media"; |
5 | 5 |
|
6 | 6 | const createMockMediaMatcher = matches => () => ({ |
7 | 7 | matches, |
8 | 8 | addListener: () => {}, |
9 | 9 | removeListener: () => {} |
10 | | -}) |
| 10 | +}); |
11 | 11 |
|
12 | 12 | describe("A <Media>", () => { |
13 | | - let originalMatchMedia |
| 13 | + let originalMatchMedia; |
14 | 14 | beforeEach(() => { |
15 | | - originalMatchMedia = window.matchMedia |
16 | | - }) |
| 15 | + originalMatchMedia = window.matchMedia; |
| 16 | + }); |
17 | 17 |
|
18 | 18 | afterEach(() => { |
19 | | - window.matchMedia = originalMatchMedia |
20 | | - }) |
| 19 | + window.matchMedia = originalMatchMedia; |
| 20 | + }); |
21 | 21 |
|
22 | | - let node |
| 22 | + let node; |
23 | 23 | beforeEach(() => { |
24 | | - node = document.createElement("div") |
25 | | - }) |
| 24 | + node = document.createElement("div"); |
| 25 | + }); |
26 | 26 |
|
27 | 27 | describe("with a query that matches", () => { |
28 | 28 | beforeEach(() => { |
29 | | - window.matchMedia = createMockMediaMatcher(true) |
30 | | - }) |
| 29 | + window.matchMedia = createMockMediaMatcher(true); |
| 30 | + }); |
31 | 31 |
|
32 | 32 | describe("and a children element", () => { |
33 | 33 | it("renders its child", () => { |
34 | 34 | const element = ( |
35 | 35 | <Media query=""> |
36 | 36 | <div>hello</div> |
37 | 37 | </Media> |
38 | | - ) |
| 38 | + ); |
39 | 39 |
|
40 | 40 | ReactDOM.render(element, node, () => { |
41 | | - expect(node.firstChild.innerHTML).toMatch(/hello/) |
42 | | - }) |
43 | | - }) |
44 | | - }) |
| 41 | + expect(node.firstChild.innerHTML).toMatch(/hello/); |
| 42 | + }); |
| 43 | + }); |
| 44 | + }); |
45 | 45 |
|
46 | 46 | describe("and a children function", () => { |
47 | 47 | it("renders its child", () => { |
48 | 48 | const element = ( |
49 | | - <Media query="">{matches => (matches ? <div>hello</div> : <div>goodbye</div>)}</Media> |
50 | | - ) |
| 49 | + <Media query=""> |
| 50 | + {matches => (matches ? <div>hello</div> : <div>goodbye</div>)} |
| 51 | + </Media> |
| 52 | + ); |
51 | 53 |
|
52 | 54 | ReactDOM.render(element, node, () => { |
53 | | - expect(node.firstChild.innerHTML).toMatch(/hello/) |
54 | | - }) |
55 | | - }) |
56 | | - }) |
| 55 | + expect(node.firstChild.innerHTML).toMatch(/hello/); |
| 56 | + }); |
| 57 | + }); |
| 58 | + }); |
57 | 59 |
|
58 | 60 | describe("and a render function", () => { |
59 | 61 | it("renders its child", () => { |
60 | | - const element = <Media query="" render={() => <div>hello</div>} /> |
| 62 | + const element = <Media query="" render={() => <div>hello</div>} />; |
61 | 63 |
|
62 | 64 | ReactDOM.render(element, node, () => { |
63 | | - expect(node.firstChild.innerHTML).toMatch(/hello/) |
64 | | - }) |
65 | | - }) |
66 | | - }) |
67 | | - }) |
| 65 | + expect(node.firstChild.innerHTML).toMatch(/hello/); |
| 66 | + }); |
| 67 | + }); |
| 68 | + }); |
| 69 | + }); |
68 | 70 |
|
69 | 71 | describe("with a query that does not match", () => { |
70 | 72 | beforeEach(() => { |
71 | | - window.matchMedia = createMockMediaMatcher(false) |
72 | | - }) |
| 73 | + window.matchMedia = createMockMediaMatcher(false); |
| 74 | + }); |
73 | 75 |
|
74 | 76 | describe("and a children element", () => { |
75 | 77 | it("renders its child", () => { |
76 | 78 | const element = ( |
77 | 79 | <Media query=""> |
78 | 80 | <div>hello</div> |
79 | 81 | </Media> |
80 | | - ) |
| 82 | + ); |
81 | 83 |
|
82 | 84 | ReactDOM.render(element, node, () => { |
83 | | - expect(node.firstChild.innerHTML || "").not.toMatch(/hello/) |
84 | | - }) |
85 | | - }) |
86 | | - }) |
| 85 | + expect(node.firstChild.innerHTML || "").not.toMatch(/hello/); |
| 86 | + }); |
| 87 | + }); |
| 88 | + }); |
87 | 89 |
|
88 | 90 | describe("and a children function", () => { |
89 | 91 | it("renders its child", () => { |
90 | 92 | const element = ( |
91 | | - <Media query="">{matches => (matches ? <div>hello</div> : <div>goodbye</div>)}</Media> |
92 | | - ) |
| 93 | + <Media query=""> |
| 94 | + {matches => (matches ? <div>hello</div> : <div>goodbye</div>)} |
| 95 | + </Media> |
| 96 | + ); |
93 | 97 |
|
94 | 98 | ReactDOM.render(element, node, () => { |
95 | | - expect(node.firstChild.innerHTML).toMatch(/goodbye/) |
96 | | - }) |
97 | | - }) |
98 | | - }) |
| 99 | + expect(node.firstChild.innerHTML).toMatch(/goodbye/); |
| 100 | + }); |
| 101 | + }); |
| 102 | + }); |
99 | 103 |
|
100 | 104 | describe("and a render function", () => { |
101 | 105 | it("does not render", () => { |
102 | | - let renderWasCalled = false |
| 106 | + let renderWasCalled = false; |
103 | 107 | const element = ( |
104 | 108 | <Media |
105 | 109 | query="" |
106 | 110 | render={() => { |
107 | | - renderWasCalled = true |
108 | | - return <div>hello</div> |
| 111 | + renderWasCalled = true; |
| 112 | + return <div>hello</div>; |
109 | 113 | }} |
110 | 114 | /> |
111 | | - ) |
| 115 | + ); |
112 | 116 |
|
113 | 117 | ReactDOM.render(element, node, () => { |
114 | | - expect(node.firstChild.innerHTML || "").not.toMatch(/hello/) |
115 | | - expect(renderWasCalled).toBe(false) |
116 | | - }) |
117 | | - }) |
118 | | - }) |
119 | | - }) |
| 118 | + expect(node.firstChild.innerHTML || "").not.toMatch(/hello/); |
| 119 | + expect(renderWasCalled).toBe(false); |
| 120 | + }); |
| 121 | + }); |
| 122 | + }); |
| 123 | + }); |
120 | 124 |
|
121 | 125 | describe("rendered on the server", () => { |
122 | 126 | beforeEach(() => { |
123 | | - window.matchMedia = createMockMediaMatcher(true) |
124 | | - }) |
| 127 | + window.matchMedia = createMockMediaMatcher(true); |
| 128 | + }); |
125 | 129 |
|
126 | 130 | it("renders its child", () => { |
127 | 131 | const markup = ReactDOMServer.renderToStaticMarkup( |
128 | 132 | <Media query=""> |
129 | 133 | <div>hello</div> |
130 | 134 | </Media> |
131 | | - ) |
| 135 | + ); |
132 | 136 |
|
133 | | - expect(markup).toMatch(/hello/) |
134 | | - }) |
135 | | - }) |
136 | | -}) |
| 137 | + expect(markup).toMatch(/hello/); |
| 138 | + }); |
| 139 | + }); |
| 140 | +}); |
0 commit comments