File tree Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
import PropTypes from "prop-types" ;
3
+ import invariant from "invariant" ;
3
4
import json2mq from "json2mq" ;
4
5
5
6
/**
@@ -31,15 +32,14 @@ class Media extends React.Component {
31
32
componentWillMount ( ) {
32
33
if ( typeof window !== "object" ) return ;
33
34
34
- let { query } = this . props ;
35
35
const targetWindow = this . props . targetWindow || window ;
36
36
37
- if ( ! targetWindow . matchMedia ) {
38
- throw new Error (
39
- 'You passed a `targetWindow` prop to `Media` that does not have a `matchMedia` function.'
40
- ) ;
41
- }
37
+ invariant (
38
+ typeof targetWindow . matchMedia === "function" ,
39
+ "<Media targetWindow> does not support `matchMedia`."
40
+ ) ;
42
41
42
+ let { query } = this . props ;
43
43
if ( typeof query !== "string" ) query = json2mq ( query ) ;
44
44
45
45
this . mediaQueryList = targetWindow . matchMedia ( query ) ;
Original file line number Diff line number Diff line change @@ -155,9 +155,9 @@ describe("A <Media>", () => {
155
155
156
156
expect ( ( ) => {
157
157
ReactDOM . render ( element , node , ( ) => { } ) ;
158
- } ) . toThrow ( "does not have a `matchMedia` function " ) ;
158
+ } ) . toThrow ( "does not support `matchMedia`" ) ;
159
159
} ) ;
160
- } )
160
+ } ) ;
161
161
} ) ;
162
162
163
163
describe ( "rendered on the server" , ( ) => {
Original file line number Diff line number Diff line change 24
24
"react" : " >=15 || ^0.14.7"
25
25
},
26
26
"dependencies" : {
27
+ "invariant" : " ^2.2.2" ,
27
28
"json2mq" : " ^0.2.0" ,
28
29
"prop-types" : " ^15.5.10"
29
30
},
You can’t perform that action at this time.
0 commit comments