import * as effects from 'src/effects'
/**
 * @jest-environment jsdom
 */
jest.useFakeTimers()

describe('Effects', () => {
  let element
  beforeEach(() => {
    element = document.createElement('div')
    document.body.appendChild(element)
  })
  afterEach(() => {
    document.body.innerHTML = ''
  })
  test('Fade in', () => {
    element.style.opacity = 1
    effects.fadeIn(element, 100)
    expect(Number(element.style.opacity)).toBeGreaterThanOrEqual(0)
    jest.runAllTimers()
    expect(Number(element.style.opacity)).toBeGreaterThanOrEqual(1)
  })
  test('RAF fade in', () => {
    window.requestAnimationFrame = jest.fn(fn => setTimeout(fn, 1))
    effects.fadeIn(element, 1)
    jest.runAllTimers()
    expect(window.requestAnimationFrame).toBeCalled()
    effects.fadeIn(element)
    jest.runAllTimers()
    expect(window.requestAnimationFrame).toBeCalled()
    delete window.requestAnimationFrame
  })
  test('Fade out', () => {
    element.style.opacity = 0
    effects.fadeOut(element, 100)
    expect(Number(element.style.opacity)).toBeLessThanOrEqual(1)
    jest.runAllTimers()
    expect(Number(element.style.opacity)).toBeLessThanOrEqual(0)
  })
  test('Hide', () => {
    effects.hide(element)
    expect(element.style.display).toBe('none')
  })
  test('Show', () => {
    effects.show(element)
    expect(element.style.display).toBe('')
  })
})

@@ -586,22 +586,22 @@
 %3E %7B%0A    
-window
+global
 .request
@@ -629,31 +629,8 @@
 .fn(
-fn =%3E setTimeout(fn, 1)
 )%0A  
@@ -685,38 +685,38 @@
 rs()%0A    expect(
-window
+global
 .requestAnimatio
@@ -799,22 +799,22 @@
  expect(
-window
+global
 .request
@@ -857,14 +857,14 @@
 ete 
-window
+global
 .req

Fix fade test with RAF