const {before} = require('mocha')

before(mockDOM)
before(mockCustomElements)
before(mockConnectedCallback)
// before(setChaiAssertions)

function mockDOM() {
  const {JSDOM: Dom} = require('jsdom')
  const dom = new Dom('<!doctype html><html><body></body></html>')
  global.document = dom.window.document
  global.window = document.defaultView
  window.Object = Object
  window.Math = Math
  global.NodeList = window.NodeList
  global.HTMLElement = window.HTMLElement
  global.environment = 'node'
}

function mockCustomElements() {
  require('document-register-element/pony')(window)
}

function mockConnectedCallback() {
  // jsdom dont call connectedCallback on appendChild, native customElements call connectedCallback
  const {Element} = window
  const appendChild = Element.prototype.appendChild
  Element.prototype.appendChild = function(element){
    appendChild.apply(this, arguments)
    if (element && element.connectedCallback) {
      element.connectedCallback()
    }
  }
}

// function setChaiAssertions() {
//   require('chai')
//     .use(require('chai-dom'))
// }

@@ -104,37 +104,8 @@
 ack)
-%0A// before(setChaiAssertions)
 %0A%0Afu
@@ -957,98 +957,4 @@
 %7D%0A%7D%0A
-%0A// function setChaiAssertions() %7B%0A//   require('chai')%0A//     .use(require('chai-dom'))%0A// %7D%0A

delete trash comments from before unit tests