         expect(overlayDOM.style.cssText).to.not.contain('height')
 
   it 'should set overlay height and be scrollable if overlay height is greater than window height', ->
-    window = {}
+    window = _.clone(FAKE_WINDOW)
 
     Testing
       .renderComponent( PopoverWrapper )
       .then ({dom, element}) ->
         {overlay} = element.refs
         {popper} = overlay.refs
-
+        fakePopoverShouldScroll(popper)
         Testing.actions.click(dom)
-        fakePopoverShouldScroll(popper, window)
         overlayDOM = popper.getOverlayDOMNode()
 
         expect(overlayDOM.style.cssText).to.contain('height')

  expect(popcontentDOM.innerHTML).to.equal(html)
  expect(overlayDOM.innerHTML).to.contain(html)

fakePopoverShouldRight = (popperElement, window) ->
  popperElement.calcOverlayPosition = ->
    overlayLeft: 100
  window.innerWidth = 800

fakePopoverShouldLeft = (popperElement, window) ->
  popperElement.calcOverlayPosition = ->
    overlayLeft: 600
  window.innerWidth = 800

fakePopoverShouldScroll = (popperElement, window) ->
  calledOnce = false
  window.innerHeight = 600

  getOverlayDOMNode = popperElement.getOverlayDOMNode
  popperElement.getOverlayDOMNode = ->

        expect(overlay.state.show).to.be.false

  it 'should open to the right when element renders left of the window middle', ->
    window = _.clone(FAKE_WINDOW)

    Testing
      .renderComponent( PopoverWrapper )
      .then ({dom, element}) ->
        {overlay} = element.refs
        {popper} = overlay.refs
        fakePopoverShouldRight(popper)
        Testing.actions.click(dom)
        overlayDOM = popper.getOverlayDOMNode()

