File tree Expand file tree Collapse file tree 4 files changed +10
-3
lines changed
Expand file tree Collapse file tree 4 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ var Image = function (_React$Component) {
3131 var _this = _possibleConstructorReturn ( this , Object . getPrototypeOf ( Image ) . call ( this ) ) ;
3232
3333 var opacity = 0 ;
34- if ( ! src . match ( / h t t p / ) ) opacity = 1 ;
34+ if ( ! src . match ( / h t t p / ) || typeof window === 'undefined' ) opacity = 1 ;
3535
3636 _this . state = { opacity : opacity } ;
3737 return _this ;
Original file line number Diff line number Diff line change 11{
22 "name" : " legit-image" ,
3- "version" : " 0.1.2 " ,
3+ "version" : " 0.1.3 " ,
44 "description" : " an img tag, with built in lazy loading" ,
55 "main" : " lib/image.js" ,
66 "scripts" : {
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export default class Image extends React.Component {
55 constructor ( { src } ) {
66 super ( )
77 let opacity = 0
8- if ( ! src . match ( / h t t p / ) ) opacity = 1
8+ if ( ! src . match ( / h t t p / ) || typeof window === 'undefined' ) opacity = 1
99
1010 this . state = { opacity }
1111 }
Original file line number Diff line number Diff line change @@ -5,10 +5,17 @@ import Image from '../src/image'
55
66describe ( 'Image' , ( ) => {
77 it ( 'renders with opacity: 0' , ( ) => {
8+ global . window = { }
89 const wrapper = shallow ( < Image src = "http://google.com" /> )
910 expect ( wrapper . props ( ) . style . opacity ) . to . equal ( 0 )
1011 } )
1112
13+ it ( 'renders with opacity: 1 on server' , ( ) => {
14+ global . window = undefined
15+ const wrapper = shallow ( < Image src = "http://google.com" /> )
16+ expect ( wrapper . props ( ) . style . opacity ) . to . equal ( 1 )
17+ } )
18+
1219 it ( 'changes opacity on state change' , ( ) => {
1320 const wrapper = shallow ( < Image src = "http://google.com" /> )
1421 wrapper . setState ( { opacity : 1 } )
You can’t perform that action at this time.
0 commit comments